Mithun Debnath
Mithun Debnath

Reputation: 588

regex to ignore certain pattern

String link[] = text.split("\\b");

I am using this code to split my line of text. The problem here is if my sentence contains "-" for example mithun-debnath then also it is separating the sentence. My objective is to split the sentence with all possible delimiters except "-".i.e. if the sentence "yes,i love my country very-much" then my array should contain link[0]=yes link[1]=i link[2]=love link[3]=my link[4]=country link[5]=very-much.I have not able to come out with an way to ignore "-" in ("\b").

Upvotes: 1

Views: 628

Answers (1)

vks
vks

Reputation: 67968

String link[] = text.split("(?!-)(?<!-)\\b");

Add a lookahead for the same.See demo.

https://regex101.com/r/mG8kZ9/2

Upvotes: 1

Related Questions