2012-06-20 56 views
1

我看了here,並從我的理解,以下正則表達式只是意味着「任何Unicode字符序列」。有人可以確認這個嗎?正則表達式中解釋

當前正則表達式:/^+ $/U

另外,如果我讀它說

一)\ p {M上的手動(> \ P {M} \ p {M} *?) ?} = \ PM

b)(> \ PM \ PM *)= \ X

所以在手這兩樣東西,我不能簡化正則表達式?:

建議正則表達式:/^ \ X + $/u

這我還沒有真正理解...

+0

好,根據你是對的anual。但是,問題是什麼? –

+0

[我閱讀正則表達式文檔](http://thejoysofcode.tumblr.com/post/35331265331/when-i-am-forced-to-read-regex-documentation) –

回答

2

是,\P{M}\p{M}*可以簡化爲\X,但不是所有的語言都支持\X而(在我的經驗)\P{M}\p{M}更頻繁的支持。

例如,Java和.NET的正則表達式引擎不支持\X(Perl當然是......)。

更多信息,請參見:http://www.regular-expressions.info/unicode.html

2
^   # start of string followed by 
(?>   # an independent (non-backtracking) capturing group containing 
    \P{M} # a single unicode character which is not in the `Mark` category 
    \p{M}* # 0 or more characters in the `Mark` category 
)+   # with this capturing group repeated 1 or more times 
$   # the end-of-line 

^\X+$不包含捕獲組; \P{M}\p{M}*是等價的。

+0

這也是一個非常有用的答案,但我可以只接受一個,巴特的答案就是我所尋找的。 –