1
我無法弄清楚如何用正則表達式來做到這一點。我想在句子中的一定數量的字符後匹配句號。PHP正則表達式在一定數量的字符後匹配句號
this is a long sentence. it contains a few full stops in it. I want to match the full stop after the halfway point.
this sentence is shorter. it also contains full stops but not many.
它不應該匹配最後一個句號。它應該匹配第一句中的第二句句號,並且在第二句中不匹配。所以比賽應該是這樣的:
this is a long sentence. it contains a few full stops in it[.] I want to match the full stop after the halfway point.
this sentence is shorter. it also contains full stops but not many. [no match]
有沒有辦法做到這一點?我沿着這不工作在所有線的東西:
/[.]{20,}/
這聽起來很模糊。請參閱['。{30,}?\ K \。(?=。{30,})'](https://regex101.com/r/P6JIa5/2/),它只會匹配30或30之後的點。更多的字符,如果跟着30個或更多的字符。 –
這很快,我還沒有完成編輯問題。這是不是匹配?它實際上是一個preg_split。 – Hasen
WiktorStribiżew解決方案效果不錯 –