How to ignore "periods" in quotes

I want to ignore .

quotes. what should i use regex?

example sentences:

String sentence = "i love you. \"i'm sorry. but love someone else,\" he said to me. ";

      

there are three .

, but I want to ignore .

the quotes so that the sentence sum is two.

my code and some regex I have:

public static String[] ignoreWord(String word){
String [] arrWords = word.replaceAll(", *| , *|- *| - *|\\( *| \\( *|\\) *|\\{ *| \\} *| \\} *| \\{*|\\} *", " ").split("\\. ");
return arrWords;
}

      

+3


source to share


1 answer


\.(?=(?:[^"]*"[^"]*")*[^"]*$)

      

Try it. Check out the demo.



http://regex101.com/r/zX3tG3/1

+3


source







All Articles