in reply to Re: Regex not working
in thread Regex not working

Not working in that nothing changes with the input

Desired output from

<color=blue><i><b> <br>Some text</color>,  <br>an a

would be..

[color=blue]<i><b> <br>Some text[/color],  <br>an a

Replies are listed 'Best First'.
Re^3: Regex not working
by Beaker (Beadle) on Jul 17, 2015 at 16:10 UTC
    Sorry struggling to use this website, can't seem to edit my post. The input is given in my first post, ignore the input in my second post as it's incorrect. The expected output is correct.

      If I hold the first post as input, then your last post as correct output, I too get the expected output...

      !/usr/bin/perl use strict; use warnings; my $text; while($text=<DATA>){ $text =~ s~<font color=("|')?((\w|\s)+)("|')?>(.*?)<\/font>~\[ +color=$2\]$5\[/color\]~ig; print $text . "\n"; } # expected output: # [color=blue]<i><b> <br>Some text[/color], <br>an a __DATA__ <font color="blue"><i><b> <br>Some text</font>, <br>an a

      Yields:

      [color=blue]<i><b> <br>Some text[/color], <br>an a

      Can you, maybe, explain in words? or have a larger sample set. Do you mean that this works, but when it is multi-line, then it doesn't match?

        Thanks, I wonder then if it could be an encoding issue with my input, not sure the best way to check that.

      To edit your own posts, simply click on the title, and an edit box will appear at the bottom of your post.

        thanks