Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does the regex pattern 'pL' do? [duplicate]

There is a common Regex used to slugify urls ~[^\\pL\d]+~u but what does the\\pL in the first preg_replace() mean?

Here are some examples:

  • How can I replace ":" with "/" in slugify function?
  • http://snipplr.com/view/22741/slugify-a-string-in-php/
  • http://sourcecookbook.com/en/recipes/8/function-to-slugify-strings-in-php
  • http://www.daniweb.com/web-development/php/threads/471380/php-slugify-two-variables-together
like image 972
Adrian Avatar asked Apr 17 '14 13:04

Adrian


People also ask

What is pL in regex?

\\pL is a Unicode property shortcut. It can also be written as as \p{L} or \p{Letter} . It matches any kind of letter from any language.

What does regex pattern do?

A regular expression (shortened as regex or regexp; sometimes referred to as rational expression) is a sequence of characters that specifies a search pattern in text. Usually such patterns are used by string-searching algorithms for "find" or "find and replace" operations on strings, or for input validation.

What is P Java regex?

This character class \p{javaMirrored} matches upper case letters. This class matches the characters which returns true when passed as a parameter to the isMirrored() method of the java.

How do you repeat a regular expression?

A repeat is an expression that is repeated an arbitrary number of times. An expression followed by '*' can be repeated any number of times, including zero. An expression followed by '+' can be repeated any number of times, but at least once.


2 Answers

\\pL is a Unicode property shortcut. It can also be written as as\p{L} or \p{Letter}. It matches any kind of letter from any language.

like image 158
Amal Murali Avatar answered Sep 18 '22 23:09

Amal Murali


\\pL is a shorthand for \\p{L}

reference

In addition to the standard notation, \p{L}, Java, PHP, Perl, PCRE and the JGsoft engine allow you to use the shorthand \pL. The shorthand only works with single-letter Unicode properties. \pLl is not the equivalent of \p{Ll}. It is the equivalent of \p{L}l which matches Al or àl or any Unicode letter followed by a literal l.

like image 20
hsz Avatar answered Sep 20 '22 23:09

hsz