in reply to Regular expression question

If you want to combine all four, you could do:
my %repl = qw / < &lt; > &gt; foo bar bar foo /; $wrapper =~ s/([<>]|foo|bar)/$repl{$1}/g;
But other solutions are possible as well.

Abigail

Replies are listed 'Best First'.
Re: Re: Regular expression question
by TASdvlper (Monk) on Jan 16, 2004 at 16:53 UTC
    Thanks. So to expand on this a bit, I want to do that regex but not if there is a
    between the angle brackets (there probably never be white space, before and after the br, but I want to check just in case). so,
    <br> Don't do the regex < br > Don't do the regex < br> Don't do the regex <br > Don't do the regex <this> Do the regex <is> Do the regex <a> Do the regex <test> Do the regex <this is a test> Do the regex
    Thanks again ...
      #!/usr/bin/perl use strict; use warnings; undef $/; $_ = <DATA>; my %repl = qw / < &lt; > &gt; foo bar bar foo /; s/(<\s*br\s*>|[<>]|foo|bar)/$repl{$1}||$1/ge; print; __DATA__ <br> Don't do the regex < br > Don't do the regex < br> Don't do the regex <br > Don't do the regex <this> Do the regex <is> Do the regex <a> Do the regex <test> Do the regex <this is a test> Do the regex <br> Don't do the regex < br > Don't do the regex < br> Don't do the regex <br > Don't do the regex &lt;this&gt; Do the regex &lt;is&gt; Do the regex &lt;a&gt; Do the regex &lt;test&gt; Do the regex &lt;this is a test&gt; Do the regex

      Abigail

        What does this part do:
        $repl{$1}||$1/ge;
        I know the 'g' is global but I couldn't find what the 'e' is. Also, I couldn't find any info for the '||'.

        Thanks in advance.