I have a regular expression that I want to use to pull ID's out of a JSON string. The expression itself appears to work fine based on the data I've given it, so that's good.
^(?:.*)(?:{"id":)(\d+)(?:.*)$
Unfortunately, it involves more than one non-capturing group ("(?:)"), and that seems to break Apex with the dreaded "Invalid regex at index 9." Is there actually a 1 non-capture group limit in Apex's regex flavor or is there something else wrong with this? I wasn't able to find any documentation on such a limit, so i'm inclined to think that there is some other error in my regex, but I can't find it!
Just for completeness, here's an example that is failing on my sandbox.
pattern myPattern = pattern.compile('^(?:.*)(?:{"id":)$');
matcher myMatcher = myPattern.matcher('{"user":{"id":11111,"userName":');
System.assert(myMatcher.matches() && myMatcher.hitEnd());
if(myMatcher.matches())
{
system.debug(myMatcher.group(1));
}
* bolded for easier skimming
11111
? My regex is a tad rusty but I don't see you actually capturing any information. Also with the $ indicating the end of the string wouldn't the regex you provided stop before getting to the11111
?^(?:.*?)(?:{"id":)$