Regexes have limitations with stream parsing but something like this will probably do the trick. You need the 1 while as in the last example the first pass removes the inner null tag pair and the second pass removes the enclosing pair now that the inner null pair has been replaced by a null string. By nothing between I have taken that to be literal. I have also assumed that the general syntax is [blah...]...[/blah].
The capture into $1 (\1) assumes there is no space between the [ and the blah.... If it is not well formed (ie humans, not a machine generated it) it is generally useful to put lots of \s* tokens into the RE so that it can deal with [ blah=foo] [ / blah]
local $/; $_ = <DATA>; 1 while s#\[(\w+)[^\]]*\]\[/\1\]##ig; print; __DATA__ [b]bold text[/b] [color=Red]Red text text[/color] [color=Red][b]Red bold text[/b][/color] I need to remove the ones below: [b][/b] [color=Red][/color] [color=Red][b][/b][/color]
cheers
tachyon
In reply to Re: Regex help
by tachyon
in thread Regex help
by kiat
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |