I am trying to replace in-between periods and exclamations i.e.,(.,!) with comma. When I tried, my code replaces all the fullstops(.) with comma(,) but, I dont want to change the ending fullstop.
String txt="When I'm bored, I eat. When I'm happy, I eat. When I'm sad, I eat.";
txt = txt.replaceAll("[^\\x00-\\x7f-\\x80-\\xad]", ""); //replaces emojies
//String a=txt.replaceAll("[.!]", ","); //replaces comma or exclamation
System.out.println(txt);
OUTPUT WITH LINE COMMENTED OUT:
When I'm bored, I eat. When I'm happy, I eat. When I'm sad, I eat.
OUTPUT WITH CODE INSTEAD OF COMMENT (and println(a)
):
When I'm bored, I eat, When I'm happy, I eat, When I'm sad, I eat,