The script you posted is working perfectly fine. There must be a problem with the actual input you are using. That being said there's quite a lot you could do to improve the RegExp:
((\w|\s)+) is better written as a character class, e.g.: ([\w\s]+)
Are you sure this is what you want? According to W3C there are no HTML-colors with whitespace in their name.
Use \s*(\w+)\s* instead? Additionally you fail to match valid colors like #ff0000
("|')? .... ("|')? -> would match "abc'; better use a back-reference: (["']?) .... \1
<\/font> can be replaced with </font> since you are using s~~~ instead of s///
\[color=$2\]$5\[/color\] can be converted into [color=$2]$5\[/color] (must keep the escape after $5 or perl complains)
Additionally: I don't know where the input is coming from and how you much you can trust it. Your code 'fails open' - nothing happens in case it fails to match. I would suggest to convert it into 'fail closed' - complain loudly or even terminate in case a font tag can not be matched propely.
while (parse input) {
if (a font tag is found)) {
if (font tag matches expected pattern) {
(replace font tag)
}
else {
(complain loudly)
}
}
}
In reply to Re: Regex not working
by Monk::Thomas
in thread Regex not working
by Beaker
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |