Login  Register

Re: Regex macros and capturing groups

Posted by Hugo <Nabble> on Feb 25, 2013; 6:47pm
URL: https://support.nabble.com/Regex-macros-and-capturing-groups-tp7583348p7583369.html

Thanks for reporting this, David. I am trying to reproduce the problem, but I am not sure I understand the whole issue. For example, consider this code:
<macro name="test">
    <n.regex_replace_all. pattern="(a)(b)(c)" replacement="$1-$2-$3">
        begin abc end
    </n.regex_replace_all.>    
</macro>
This code can be easily tested with a URL like this:
<your-app-domain>/template/NamlServlet.jtp?macro=test

This code above works fine (it prints "begin a-b-c end"). 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.

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!