Regex macros and capturing groups
Posted by
DavidJCobb on
Feb 25, 2013; 5:50am
URL: https://support.nabble.com/Regex-macros-and-capturing-groups-tp7583348.html
If, during a regex operation, you attempt to access a capturing group that isn't there (through either <n.did_find group="x"/> or through "$x" codes in a replacement string), NAML completely chokes. There's no way to catch or handle the relevant exception, which can cause some clunkiness when designing certain systems (in my case, a profile customization system that uses a list of regexes to process different URLs for different profile options).
It's my understanding that this is because Java itself throws an exception, and I'm aware that you guys are working on an overhaul for the forum software, so I'll understand if this is left alone. Thought it'd be good to point it out, though.
On a related note, sorry about recent very high bandwidth consumption on Testing Perfection. I was trying out some regex manipulation in an attempt to work around that above problem... Tip: never put "()" in a regex. Not even once. :\
EDIT: Apparently, ^(a)(b)(c)$ also causes it to choke -- this time with a server crash, not an exception. Which is weird enough that I'm starting to think I'm not the problem... :\
EDIT2: I'm gonna leave it alone for a few days, and see if I can find a non-server-based Java app to jam some regexes into.
For those who are curious about the crashing business, the basic problem is that if you try to run /(a)(b)(c)/ and use a replacement string "$1$2$3$4", that's one group too many, so you get an exception. This is bad if you need to have a varied set of regexes run through one piece of code. I was trying to work around this by having my regex call append dummy capturing groups to the end of the regex variable, with the intent of creating additional capturing groups without actually affecting what gets matched; this way, there would always be enough groups to prevent an exception. Unfortunately, regexes can be very dangerous when you're doing particularly... eccentric... things with them -- something I had previously forgotten about, and was rather alarmingly reminded of when Testing Perfection went down.