You can also match case insensitive regexs and make it more readable by using the Pattern.CASE_INSENSITIVE constant like:
Pattern mypattern = Pattern.compile(MYREGEX, Pattern.CASE_INSENSITIVE);
Matcher mymatcher= mypattern.matcher(mystring);
Answer from Christian Vielma on Stack OverflowYou can also match case insensitive regexs and make it more readable by using the Pattern.CASE_INSENSITIVE constant like:
Pattern mypattern = Pattern.compile(MYREGEX, Pattern.CASE_INSENSITIVE);
Matcher mymatcher= mypattern.matcher(mystring);
RegexBuddy is telling me if you want to include it at the beginning, this is the correct syntax:
"(?i)\\b(\\w+)\\b(\\s+\\1)+\\b"
java - Match strings with regular expression in ignore case - Stack Overflow
regex to ignore case
You have to put the entirety of what you want matched inside a set of parenthesis. In your case, it would look like the following: ((?i)user.name)
Let me know if that helped.
More on reddit.comregex - Java - Ignore case checking user input - Stack Overflow
java - ignore case regex - Stack Overflow
I wouldn't use RegEx for everything.
for(String str : ar)
{
if(!str.toUpperCase().startsWith("KB"))
System.out.println(str);
}
From the way your question is worded, I'm not entirely sure whether you want the match to be case insensitive or not. This regex:
(?i)[^k][^b].*
uses the flag (?i) to turn off case sensitivity, and should do want you want.
Hi
working on a regex to ignore case when looking for a username e.g. User.Name or user.Name or USER.NAME. add filter - Username matches any of expressions (i?)(user).(name) also tried i?(user.name) or i (user.name). But neither work.
You have to put the entirety of what you want matched inside a set of parenthesis. In your case, it would look like the following: ((?i)user.name)
Let me know if that helped.
all major regex help sites say (?i) is the correct java 7 syntax but Qradar regex engine spits errors.
so no one else is having issues with case-insensitive flag?
You can try Pattern.CASE_INSENSITIVE with the Pattern.
I don't understand why you can't use String.equalsIgnoreCase(). Regex is not needed for this. If you use a List, you can use .stream().anyMatch() with this Predicate:
c -> c.equalsIgnoreCase(data)
Code Sample:
public static void main(String[] args) throws Exception {
List<String> check = new ArrayList() {{
add("dog");
add("CAT");
add("oWl");
add("GiraFFe");
}};
Scanner scanner = new Scanner(System.in);
System.out.print("Enter data: ");
String data = scanner.nextLine();
if (check.stream().anyMatch(c -> c.equalsIgnoreCase(data))) {
System.out.println("Data found");
} else {
System.out.println("Data not found");
}
}
Results:
Enter data: gIRAffE
Data found
Enter data: lamb
Data not found
You need to use JAVA-like CASE_INSENSITIVE pattern (?i)
Something like this:
Pattern staPattern = Pattern.compile('(?i)STA[0-9]{4}');
To make it case insensitive, you can just modify your pattern as follows
Pattern staPattern = Pattern.compile('[Ss][Tt][Aa][0-9]{4}');
This can be long winded if you have a long pattern, so then you use the ignore case modifier
Pattern staPattern = Pattern.compile('(?i)sta[0-9]{4}');