I have this regex:
^((?:(?:\s*[a-zA-Z0-9]+)*)?)\s*function\s+([_a-zA-Z0-9]+)\s+\(\s*(.*)\s*\)\s*
to match this line:
public function private ($var,Type $typed, $optional = 'option');
This works, but when it comes to this:
public function privateX ($var,Type $typed, $optional = 'option');
Fails.
I noticed that when a function name is longer than 6 characters, it no longer matches.
Here is the complete code:
$strA = 'public function 6Chars ($var,Type $typed, $optional = "option");';
$strB = 'public function MoreThan7 ($var,Type $typed, $optional = "option");';
preg_match('!^((?:(?:\s*[a-zA-Z0-9]+)*)?)\s*function\s+([_a-zA-Z0-9]+)\s+\(\s*(.*)\s*\)\s*!',$strA,$mA);
preg_match('!^((?:(?:\s*[a-zA-Z0-9]+)*)?)\s*function\s+([_a-zA-Z0-9]+)\s+\(\s*(.*)\s*\)\s*!',$strB,$mB);
print_r($mA);
print_r($mB);
My question is pretty simple: why doesn't the second line match?
dader source
share