2013-06-19 51 views
1

目前我有這個正則表達式將一個段落拆分成句子:/[^\.!\?]+[\.!\?]+/g。但問題是我的段落不僅僅是文本的段落。我有一個像這樣在他們的聯繫:如何構建將段落拆分爲句子的正則表達式,但是不會拆分<>中的任何標點符號?

This is text and here is a <value="link" href="http://link.com?param=test"> which directs to another page. So I don't want to split at the anything inside the link above. 

我想是分成像數組:

['This is text and here is a <value="link" href="http://link.com?param=test"> which directs to another page.', 'So I don't want to split at the anything inside the link above.'] 

什麼正則表達式將做到這一點?

回答

1

試試這個:

(.+?[\.!\?](?!.+?>)\s*) 
+0

這似乎是工作得很好,但忘掉過去的文本,如果它不能在預期的標點符號結束時分裂。 – Namey