Login  Register

Re: Regex macros and capturing groups

Posted by DavidJCobb on Feb 26, 2013; 6:04am
URL: https://support.nabble.com/Regex-macros-and-capturing-groups-tp7583348p7583384.html

Hugo <Nabble> wrote
If the replacement has a fourth group ($1-$2-$3-$4) we do get an exception: "No group 4", caused by an IndexOutOfBoundsException. It should be easy to catch these exceptions in the java code and re-throw them as template exceptions that can be handled with NAML. If you think this makes sense, we can do this pretty quickly.
That makes sense and would be helpful, though I think I may have found a (non-crashing) workaround for the issue.

Hugo <Nabble> wrote
Are there other examples we should consider? I believe you can test the regex code with small macros like the one above. If the server goes down, then we should really fix the problem. I am interested in all examples you have available. Just let us know and we can fix the problems. This experience will also be important for the Lua-based implementation to be released in the near future. Thanks!
The weird thing is, I can no longer reproduce the crash. Not through regex manipulation, anyway.

The crashes occurred when I tried to work around the capturing group exception, by adding dummy capturing groups. The regular expression that led to a crash was (assuming that my NAML code was supplying the values properly):

(?i)^(?:https?\:\/\/)?(?:www\.|admin\.|halo\.)?bungie\.net\/Account\/Profile\.aspx\?(?:.*?&)*?(memberID|uid)(=\d+)(?:&.*?|)$|^()()()()()$

Where the original regex, without my workarounds, was:

(?i)^(?:https?\:\/\/)?(?:www\.|admin\.|halo\.)?bungie\.net\/Account\/Profile\.aspx\?(?:.*?&)*?(memberID|uid)(=\d+)(?:&.*?|)$

Though this appears to have been what led to a crash earlier, it now seems to work just fine. I don't have the original code that caused a crash (I didn't know that the server would be down for as long as it was, so I tried to fix the NAML mid-crash), but code that should be functionally identical is failing to break anything. So I guess it might not be regex-related. (This might be the worst bug report I've ever submitted. :P)

Well, if I see another crash, I'll leave the NAML untouched, copy down the names of the relevant macros, and post another thread here. :\