I'd like to get parts of the filename
filenameblabla_2009-001_name_surname-name_surname
I'd like to get: 2009-001, name_surname, name_surname
I've come up with this, but it's no good
preg_match("/(?:[0-9-]{8})_(?:[a-开发者_StackOverflow社区z_]+)-(?:[a-z_]+)/", $filename, $matches);
Any pointers?
Thanks! BR
Assuming filename format doesn't change:
preg_match('#(\d{4}-\d{3})_(.*?)-(.*?)$#', $filename, $match);
Updated version to handle extension:
preg_match('#(\d{4}-\d{3})_(.*?)-(.*?)\.(.*?)$#', $filename, $match);
preg_match("([0-9-]{8})_([^_]+)_([^_]+)-([^_]+)_([^_]+)$", $filename, $matches);
if your file name is always that structure
$name = "blabla_2009-001_name_surname-name_surname";
$s = explode("_",$name,3);
$t = explode("-",end($s));
print "$s[1] $t[0] $t[1]\n";
output
$ php test.php
2009-001 name_surname name_surname
Thanks you all,
I've updated my own solution As "nikc" pointed out...i just needed some direction...
here's the code if anyone will need a similar solution...
Thank you all!
preg_match('/([0-9-]{8})_([^-]+)-([a-z_]+).([a-z]+)/', $filename, $matches);
精彩评论