0

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?

Proof for regex101

valek
  • 1,365
  • 16
  • 27

2 Answers2

3

Use \p{Cyrillic} to match the cyrillic characters, i.e.:

/[\p{L}\p{Cyrillic}\s]{6,}/u

Source: Source

Ruben
  • 5,043
  • 2
  • 25
  • 49
3

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
Shira
  • 6,392
  • 2
  • 25
  • 27