Pattern, regex (regular expression) case sensitivity question
i have a clarification answer with a simple case sensitivity question with the code below
Code :
import java.util.regex.Pattern;
public class NewClass6 {
public static void main(String[] args) {
Pattern patt = Pattern.compile("[aeiou]", Pattern.CASE_INSENSITIVE);
String temp = "A";
if (temp.matches(patt.pattern())) {
System.out.println("MATCH!");
}
}
}
given that i already using Pattern class doing a bussiness with the Matcher(Pattern-matching),
in this case the String object(temp) that refers to a string value doesnt matches the pattern even if it has been compiled in a
CASE_INSENSITIVE manner..
is it because the statement patt.pattern() ONLY RETURNS a pattern, but the case sensitivity manner doesnt/cannot do anything?
Re: Pattern, regex (regular expression) case sensitivity question
Quote:
is it because the statement patt.pattern() ONLY RETURNS a pattern
Yes. You can include a case-insensitive switch in the pattern instead of using the separate flags int. See the 'Special constructs' in the API doc.