Nested Regex Targets
Posted: Sat Feb 11, 2006 4:48 pm
I ran into this problem when making an HTML filter. When searching for HTML tags, how do you handle nesting?
For example, if I search for all HTML tags, <b><i></i></b> is straightforward with ungreedy matching, but <b><i><b></b></i></b> will match the nested closing b tag with the first b tag. To get around this I made a ridiculously complex system with regexes that marked tags with numbers and recursive callbacks. Now I'm making a template system, and need to allow nested template markup, and something that slow isn't an option.
For example, if I search for all HTML tags, <b><i></i></b> is straightforward with ungreedy matching, but <b><i><b></b></i></b> will match the nested closing b tag with the first b tag. To get around this I made a ridiculously complex system with regexes that marked tags with numbers and recursive callbacks. Now I'm making a template system, and need to allow nested template markup, and something that slow isn't an option.