parsing – Regex lookaround to negate use of backreference

I’d like to update the following regedit so that I don’t need to include the tagName when closing a range. However because there exists the potential to have nested ranges, I’m unable to figure out the combination of positive/negative lookahead/lookback for the last capture group.

(?])(?:\s*)([^>]*)>(.*?[^<\/>]+)(?:<\/\1>)

regex101.com/r/g7wVCE/1

To make things easier and avoid regex recursion, any nested ranges can simply be captured as a single group, upon which I will re-evaluate that group separately until there are no more results found.

Read more here: Source link