I'm trying to implement the ideas in this post in my org. However, the provided regex seems to never match anything in any email I throw at it.
The simplest possible test case I can muster is:
string plainTextBody = 'Apex script unhandled exception by user/organization: ' + userinfo.getUserId().left(15) + '/' + userinfo.getorganizationId().left(15) + '\n';
string regex = '005[A-Za-z0-9]{12}+/(00D[A-Za-z0-9]{12}+)';
Pattern emailPattern = Pattern.compile(regex);
Matcher emailMatcher = emailPattern.matcher(plainTextBody);
for(integer i = 1; i <= emailMatcher.groupCount(); i++){
try {
system.debug(logginglevel.WARN, '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ emailMatcher.group(' + i + ') ' + emailMatcher.group(i));
} catch (exception e){
system.debug(logginglevel.WARN, '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ NOTHING IN THE GROUP');
}
}
The result of this is
14:15:26.19 (21080541)|USER_DEBUG|[12]|WARN|~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ NOTHING IN THE GROUP
Can anyone explain why my regex (or the one in the linked post) doesn't work "as advertised".