in reply to Re: regex question
in thread regex question

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"; }

Replies are listed 'Best First'.
RE: RE: Re: regex question
by swiftone (Curate) on Oct 18, 2000 at 23:20 UTC
    $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.

      In addition, if $pre and $post (the two-character versions) might be changed some day, perhaps by someone that doesn't recognize/appreciate the fact that they'll be used in a regular expression and thus might not quote them, we can use the \Q and \E codes to avoid the problem altogether:
      $pre = '**'; $post = '%%'; /(\Q$pre\E.*?\Q$first\E*\Q$post\E)/