in reply to Regex not working

I do not know why you think it does nothing:

$ cat foo.pl #!/usr/bin/perl -w use strict; use warnings; my $text = '<font color="blue"><i><b> <br>Some text</font>, <br>an a' +; $text =~ s~<font color=("|')?((\w|\s)+)("|')?>(.*?)<\/font>~\[color=$2 +\]$5\[/color\]~ig; print $text . "\n"; $ ./foo.pl [color=blue]<i><b> <br>Some text[/color], <br>an a $

That's not to say the regex couldn't be improved/simplified, but it certainly seems to have an effect as it stands.

Replies are listed 'Best First'.
Re^2: Regex not working
by Anonymous Monk on Jul 17, 2015 at 18:01 UTC
    Maybe $text actually has newlines in it and you need to add the /s modifier? Also, bracketing regex delimiters are more readable.
    $text =~ s{...}{...}igs;