I need to scroll a List and removing all strings that contains some special char. Using RegEx I’m able to remove all string that start with these special chars but, how can I find if this special char is in the middle of the string?
For instance:
Pattern.matches("[()<>/;\\*%$].*", "(123)")
returns true and I can remove this string
but it doesn’t works with this kind of string: 12(3).
Is it correct to use \* to find the occurrence of “*” char into the string?
Thanks for the help!
Andrea
You are yet another victim of Java’s ill-named
.matches()which tries and match the whole input and contradicts the very definition of regex matching.What you want is matching one character among
()<>/;\\*%$. With Java, you need to create aPattern, aMatcherfrom thisPatternand use.find()on this matcher: