in reply to Re^3: Regex help
in thread Regex help
You are probably right and as noted there are edge cases, as with all these sorts of things. Regardless of backtracking it will hit most strings at least twice. Given that I (at least) am unfamiliar with widgets that use this formatting spec I just put in a general suggestion. One of the great things about this site is that just about any hole/edge will be pointed out. Everyone learns. Something like you suggest that accurately deals with the 'blah' and 'blah=foo' forms (assumming they are the only options) with some \s* tokens to allow for whitespace issues is a little more robust. It is a pretty ugly RE but.....gotta hate metachars as formating tokens.
local $/; $_ = <DATA>; 1 while s#\[\s*(\w+)\s*(=[^\]]+)*\s*\]\s*\[\s*/\s*\1\s*\]##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] [color=Red][/col] Now this is still here ysth (if that is what is want +ed) [ b ] [ / b ] This will go now [ foo = bar ] [ / foo ] ... and this too
cheers
tachyon
|
|---|