I am trying to take a string and split it into a filename and a number
where the number is what follows the *last* instance of a comma in that
string.
Split and explode won't work because if the filename part of the original
string contains a , then I end up with too many parts.
if (!preg_match ('/^(.*),([0-9]+)$/', $string, $matches)) {throwError ();}
also fails, because the first part of the regular expression becomes
greedy if there is a , in it.
I.e. can anyone suggest a solution such that
$string = 'something.jpg, 123';
returns:
$matches['filename'] = something.jpg
$matches['number'] = 123
$string = 'something,foo. jpg,123';
returns:
$matches['filename'] = something,foo.j pg
$matches['number'] = 123
and ideally
$string = 'somethingfoo.j pg123'; // No comma contained so it's invalid
returns:
false
?
Martin Lucas-Smith www.geog.cam.ac.uk/~mvl22
Comment