我想用[,.!?;~]
分割字符串,但我想留在[,.!?;~]
其位置,例如:如何編寫正則表達式來以這種格式分割字符串?
這就是例子,但它是不夠的
要
[This is the example,, but it is not enough] // length=2
[0]=This is the example,
[1]=but it is not enough
正如你所看到的,逗號仍然存在。我用這個正則表達式(?<=([,.!?;~])+)
。 但我想如果一些特殊的單詞(例如:但是)在[,.!?;~]
之後,那麼不要拆分那部分字符串。例如:
我想把這句話分成這種形式,但怎麼辦。所以,如果 任何人都可以幫助,那將是巨大的
要
[0]=I want this sentence to be split into this form, but how to do.
[1]=So if anyone can help,
[2]=that will be great
正如你可以看到這部分(形式,但)沒有分裂INT的第一句話。
使用負前瞻。 '(?<= [,。!?;〜])(?!但)'。 –