簡體   English   中英

需要正則表達式說明

[英]Regular expression explanation required

我遇到了這個用於檢查字母字符串的正則表達式。 誰能向我解釋它的工作原理?

/^\pL++$/uD

謝謝。

\\pL+ (有時寫為\\p{L} )匹配一個或多個Unicode字母。 我更喜歡\\p{L}而不是\\pL因為還有其他Unicode屬性,例如\\p{Lu} (大寫字母)僅適用於花括號; \\pLu表示“ Unicode字母,后跟字母u ”)。

附加的+使量詞具有所有格,這意味着它將永遠不會放棄與之匹配的任何字符,即使這意味着整體匹配也會失敗。 在示例正則表達式中,這是不必要的,可以省略。

^$將匹配項固定在字符串的開頭和結尾,以確保整個字符串必須由字母組成。 沒有它們,正則表達式也將匹配由非字母包圍的子字符串。

整個正則表達式由斜杠( / )分隔。 在斜杠后,將出現PHP regex選項 u是Unicode選項(處理Unicode屬性是必需的)。 D確保$僅在字符串的末尾匹配(否則,如果該字符串以換行結尾,則它也將在該字符串的最后換行之前匹配)。

看起來像PCRE風味。

根據RegexBuddy

Assert position at the beginning of the string «^»
A character with the Unicode property “letter” (any kind of letter from any language) «\pL++»
   Between one and unlimited times, as many times as possible, without giving back (possessive) «++»
Assert position at the end of the string (or before the line break at the end of the string, if any) «$»

這看起來像Unicode處理。.我在這里找到了一篇整潔的文章,似乎可以解釋\\ pL,其余的是錨點和重復字符..在此站點上也對此進行了解釋:

http://www.regular-expressions.info/unicode.html

請享用

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM