Thanks to this post, I've discovered how to use case insensitive regular expressions.
Simply start your regular expression with "?i:". So "(?i:REGEX)" matches REGEX case insensitively.
In the code example below, one can use this to extract out an attribute value inside quotes when the attribute name is case-insensitive.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
<br />
public static void main(String[] args) {<br />
String example = "somePrefix NAME=\"value\" someSuffix";</p>
<p> Pattern p = Pattern.compile("(.*)\\s(?i:name=)(\"(.*)\")\\s(.*)");<br />
Matcher m = p.matcher(example);<br />
if (m.matches()) {</p>
<p> MatchResult mr = m.toMatchResult();</p>
<p> for( int i = 0; i &lt;= mr.groupCount(); i++) {<br />
System.out.println("Group "+i+": "+mr.group(i));<br />
}<br />
}</p>
<p> if ( m.matches() &amp;&amp; m.groupCount()&gt;=3) {<br />
System.out.println("Extracted value: "+m.group(3));<br />
}</p>
<p> }<br />
The code output yielded is:
Group 0: somePrefix NAME="value" someSuffix Group 1: somePrefix Group 2: "value" Group 3: value Group 4: someSuffix Extracted value: value