I am trying to do some string cleaning.
I want to remove all punctuation from a string except double quotes.
Below the trimPunctuation () function works fine when removing all punctuation from a string.
Does anyone know a way to remove all punctuation, but 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 information about the Unicode class Punctuation can be found here . But that did not help me.
source share