堆垛機!
我一直試圖弄清楚這一點,但沒有運氣。
(.*?(?:\.|\?|!))(?: |$)
上面的模式是用結尾標點符號捕獲和打破段落中的所有句子。
例子
- 今天是最偉大的。你是最偉大的。
比賽回來了三個 Match {
1。
今天是最偉大的。
你是最偉大的。
}
但是,當有一個帶有句點的數字時,我試圖讓它不中斷,并且希望看到以下匹配項:
Match { 1.
今天是最棒的。
你是最偉大的。
}
提前感謝您的幫助
uj5u.com熱心網友回復:
用
.*?[.?!](?=(?<!\d\.)\s |\s*$)
請參閱正則運算式證明。
解釋
--------------------------------------------------------------------------------
.*? any character except \n (0 or more times
(matching the least amount possible))
--------------------------------------------------------------------------------
[.?!] any character of: '.', '?', '!'
--------------------------------------------------------------------------------
(?= look ahead to see if there is:
--------------------------------------------------------------------------------
(?<! look behind to see if there is not:
--------------------------------------------------------------------------------
\d digits (0-9)
--------------------------------------------------------------------------------
\. '.'
--------------------------------------------------------------------------------
) end of look-behind
--------------------------------------------------------------------------------
\s whitespace (\n, \r, \t, \f, and " ") (1
or more times (matching the most amount
possible))
--------------------------------------------------------------------------------
| OR
--------------------------------------------------------------------------------
\s* whitespace (\n, \r, \t, \f, and " ") (0
or more times (matching the most amount
possible))
--------------------------------------------------------------------------------
$ before an optional \n, and the end of
the string
--------------------------------------------------------------------------------
) end of look-ahead
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/361847.html
