I am trying to do some string cleanup.
I want to remove all the punctuation from the string except double quotes.
Below trimPunctuation() function works great in removing all the punctuation from the string.
Does anyone know a way to remove all the punctuation but the double quotes.
private String trimPunctuation( String string, boolean onlyOnce )
{
if ( onlyOnce )
{
string = string.replaceAll( "\\p{Punct}$", "" );
string = string.replaceAll( "^\\p{Punct}", "" );
}
else
{
string = string.replaceAll( "\\p{Punct}+$", "" );
string = string.replaceAll( "^\\p{Punct}+", "" );
}
return string.trim();
}
More info on Punctuation unicode class can be found here. But, that didn't help me.
You can use a negative lookahead.
Rubular demo
Java example: