I am running into some problems using the regular expression. Can you please help me out?
The following in the problem I am trying to solve –
Input - :,... :(..:::))How are you today?..:(
Output - :( :) How are you today :(
Basically I want to remove the punctuations from the input string like-(.,:; etc) and replace them with empty string. But I want to keep the smilies -:) or 🙁 .I have written the following code but it is not working.
String s = ":,... :(..:::))How are you today?..:( ";
Pattern pattern = Pattern.compile("^(\\Q:)\\E|\\Q:(\\E)(\\p{P}+)");
Matcher matcher = pattern.matcher(s);
s = matcher.replaceAll("");
Thank You.
Try something like this:
A quick break down:
Note that the
[ ... && [^ ... ]](set subtraction) is unique to Java’s regex implementation. See: http://docs.oracle.com/javase/6/docs/api/java/util/regex/Pattern.html