thom
thom

Reputation: 23

PHP PCRE pattern

I want to understand the following pattern, step by step.

/\p{L}/u

/u is a modifier (http://www.php.net/manual/en/reference.pcre.pattern.modifiers.php):

u (PCRE8) This modifier turns on additional functionality of PCRE that is incompatible with Perl. > Pattern strings are treated as UTF-8. This modifier is available from PHP 4.1.0 or greater > on Unix and from PHP 4.2.3 on win32. UTF-8 validity of the pattern is checked since PHP > 4.3.5.

And what about the rest? Thank you.

Upvotes: 2

Views: 458

Answers (1)

rid
rid

Reputation: 63472

Check the PHP documentation about escape sequences to find out about \p{xx}, then Unicode character properties to find out what \p{L} does.

To elaborate:

  • the u modifier makes it possible to use Unicode escape sequences
  • \p{xx} is a Unicode sequence with a certain property
  • \p{L} is a Unicode sequence that matches a letter

Therefore, /\p{L}/u matches Unicode letters.

Upvotes: 3

Related Questions