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

Popular posts from this blog

c# - How Configure Devart dotConnect for SQLite Code First? -

java - Copying object fields -

c++ - Clear the memory after returning a vector in a function -