You need to sign in to do that
Don't have an account?
parkerAPT
Pattern groups and matching double quotes
Pattern p = Pattern.compile('.*"(.*)"');
Matcher m = p.matcher('Outer quote "test case 1"');
if(m.matches()){
for(Integer i =0 ; i < m.groupCount(); i++){
System.debug('Found Group [' + i + ']: ' + m.group(i));
}
}
Pattern p2 = Pattern.compile('.*("(.*)")');
Matcher m2 = p2.matcher('Outer quote "test case 2"');
if(m2.matches()){
for(Integer i =0 ; i < m2.groupCount(); i++){
System.debug('Found Group [' + i + ']: ' + m2.group(i));
}
}
Can someone explain why these print the following:
First pattern:
Found Group [0]: Outer quote "test case 1" {this is expected, but where is the nested group inside double-quotes?}
Second pattern:
Found Group [0]: Outer quote "test case 2" {expected}
Found Group [1]: "test case 2" {expected, but again, where is the inner group?}
Thanks!
Matcher m = p.matcher('Outer quote "test case 1"');
if(m.matches()){
for(Integer i =0 ; i < m.groupCount(); i++){
System.debug('Found Group [' + i + ']: ' + m.group(i));
}
}
Pattern p2 = Pattern.compile('.*("(.*)")');
Matcher m2 = p2.matcher('Outer quote "test case 2"');
if(m2.matches()){
for(Integer i =0 ; i < m2.groupCount(); i++){
System.debug('Found Group [' + i + ']: ' + m2.group(i));
}
}
Can someone explain why these print the following:
First pattern:
Found Group [0]: Outer quote "test case 1" {this is expected, but where is the nested group inside double-quotes?}
Second pattern:
Found Group [0]: Outer quote "test case 2" {expected}
Found Group [1]: "test case 2" {expected, but again, where is the inner group?}
Thanks!