Closed brad-jones closed 7 years ago
You're right - though the current name is a bit verbose, and I'm not sure what I'd name it. Calling it match might not be appropriate, since it returns a boolean rather than the regexp matches (preg_match in PHP, String.prototype.match in JS, re.match in python)
preg_match doesn't return the matches, it fills them via the third parameter.
You could have matchesPattern
or whatever you want to call it do likewise.
So for example:
if (s("string")->matchesPattern("pattern", $matches))
{
echo 'We found at least 1 match.';
print_r($matches);
}
Oops, you're right. That's not exactly an API I'd like to be consistent with though.
Note that the behavior would need to be changed from using mb_ereg_match to mb_ereg, since mb_ereg_match imposes ^ (matching from start of str)
Closing for now. Would like to explore an alternative API.
As per title, it would be nice to be able to do this: