joe has asked for the wisdom of the Perl Monks concerning the following question:

Replies are listed 'Best First'.
Re: regex question
by Fastolfe (Vicar) on Oct 18, 2000 at 22:45 UTC
    I don't get quite the same results as you with the code you pasted, but would a change like this do what you want?
    - @parts = split(/($pre.*?$post)/,$text); + @parts = split(/($pre.*?%*$post)/,$text);
      Thanks Fastolfe! That was the spark I needed. Here is the new code that works for me:
      $pre= "\\*\\*"; $post = "%%"; $firstchar = substr($post,0,1); $text = "**this is good%% blah **this is bad%%%%%% blah ***this is bad +%%%blah"; @parts = split(/($pre.*?$firstchar*$post)/,$text); foreach $part (@parts) { print "part: $part\n"; }
        $pre= "\\*\\*";

        You can save some eyesight by using single quotes: $pre='\*\*'

        I also came up with: my @parts = split(/($pre{2,}.*?$post{2,})/,$text); Where $pre and $post are defined as a single character.

Re: regex question
by the_slycer (Chaplain) on Oct 18, 2000 at 22:47 UTC
    Try this node for some answers :-)