I would like to remove everything what is not a character eg.
from "one,two' three . four ! Five" to "onetwothreefourFive"
I have started to write this code, but how to finish it.
How is possible to remove everything what is not a character with regex?
You could also use this:
Which is built into String as well as a shortcut:
Ireneusz Kordal wrote:
I need just the string and the Rob Prime shortcut looks very short compare to Ireneusz Kordal solution.
Are there any speed differences between the two solutions?
EDIT: Is it possible that the regular expression convert also the match to lower case?
mic ta wrote:I meant if an upper-case character is found than this character should convert to lower case, but I understand now that I am looking for non character and therefore I solve the problem with equalsIgnoreCase.
Converting to lower case is best done via the toLowerCase() method, instead of the regex related replaceAll() method. Regex is not a cure all.
mic ta wrote:EDIT: Is it possible that the regular expression convert also the match to lower case?
To answer your question.... Yes. with regex, it is possible, but not with the replaceAll() method, as it is too high level (actually, you can, but doing 26 different passes for replacements is silly).
To use regex, to convert to lower case, you will have to use the find(), appendReplacement(), and appendTail() methods.