Originally posted by ben oliver:
New to java regex. If I want to check if a String contains several special characters "a", "b" or "c" ( [abc] ), how should I do that ? a snippet ? I just want to see what method I should use...
Thanks.
Originally posted by Henry Wong:
Henry
Originally posted by ben oliver:
since I just care if the String contains "a", "b", or "c" for any times, can I do --
Pattern p = Pattern.compile("[abc]+");
Matcher m = p.matcher(text);
m.find(); // returns true if it finds any of the 3 characters for any times
Originally posted by ben oliver:
Maybe my question was too silly so nobody echoed.. Anyway, I would like to ask the same question again --
If I want to find out if a String text contains "double quote", "a", "b", or "c" for any times, can I do --
Pattern p = Pattern.compile("[\"abc]+");
Matcher m = p.matcher(text);
m.find(); // returns true if it finds any of the 3 characters for one or more occurance
Originally posted by ben oliver:
what's the difference between "[abc]" and "[abc]+" if I just want to do "find" (search) ??
"[abc]" means any of the characters in the [] (then by default it is one or more, if it is zero condition fails..)
"[abc]+" means one or more characters from the [].
So they have no difference in terms of using "find" to search. What do you think ??