regex - Replace Non-letters except apostrophe in java -
i have few strings contain non-letters.
string = "it's. (fish)[]//;!" i want return string says:
it's fish i have used string.replace() method it's bit tedious. tried using
a.replaceall("\\w", "") but removes apostrophe. there simple way of removing non-letters while keeping apostrophe?
you can use java specific construct here:
a.replaceall("[\\w&&[^']]", "") the specific construct here character class: x&&[y], meaning: match x , y. y can valid within character class.
available since java 5 if recall correctly.
Comments
Post a Comment