问题
I'm trying to validate a string using /[\p{L}\s]{6,}/
and trying to match characters only (Unicode ones as well). I used regex101 to test my regex and it works for the string Владимир Алексић
.
However, when I use that regex in preg_match()
with the same string, it always returns 0
. Yet, it returns 1 if I avoid all characters except A-Za-z
.
Why is that so?
回答1:
The \p
and other escape sequences which work with unicode character properties don't work unless the u
pattern modifier is set.
/[\p{L}\s]{6,}/u
回答2:
Use \p{Cyrillic} to match the cyrillic characters, i.e.:
/[\p{L}\p{Cyrillic}\s]{6,}/u
Source: Source
来源:https://stackoverflow.com/questions/37900273/preg-match-returns-0-although-regex-testers-work