Weird behavior with master
Closed this issue · 1 comments
e-gaulue commented
SELECT PREG_CAPTURE('/[0-9]*/','AL02814'); => ''
SELECT PREG_CAPTURE('/[0-9]+/','AL02814'); => '02814'
SELECT PREG_CAPTURE('/[0-9]*/','02814AL'); => '02814'
SELECT PREG_CAPTURE('/[0-9]+/','02814AL'); => '02814'
I don't understand the first result. Is there something I forget?
Regards,
jasny commented
PCRE will start with at the beginning of the string, try to match the regex and if it succeeds return the found string. Otherwise it will try the next character
AL02814matches? -> return matchL02814matches? -> return match02814matches? -> return match2814matches? -> return match814matches? -> return match14matches? -> return match4matches? -> return match
With /[0-9]*/ the first case actually matches. (You're looking for 0 or more digits, it has found 0.) So it returns the found match, which is an empty string.