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

心已入冬 提交于 2021-02-07 07:22:20

问题


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

回答1:


\\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.




回答2:


\\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.



来源:https://stackoverflow.com/questions/23135114/what-does-the-regex-pattern-pl-do

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!