I'm not sure if one of these is 'better' then the other, and why it would be, but I've got an original string that looks like this:
$string = '/random_length_user/file.php';
Now, there are two ways to match it, the first, using my new friend, the look-behind, and the 2nd, without:
preg_match("%(?<=^/)([^/]*)%", $string, $capture);
preg_match("%^/([^/]*)%", $string, $capture);
They return, in order:
Array
(
[0] => random_length_user
)
Array
(
[0] => /random_length_user
[1] => random_length_user
)
Essentially I get the result I want in $capture[0] using look-behind, and in $capture[1] without. Now the question is ... is there a reason to prefer one of these methods over the other?