in reply to Regarding Regular Expressions

This should do it:
$mystr =~ s/whatever/e.*fg/g;
the g looks for all occurrences.
yet if you replace the first occurence the result would be
mystr: abcdwhateverhijklfghijklabcdwhatever
which produces a new fg. If this is not what you want Id suggest:
$mystr =~ s/whatever/e.*fg/g while ( $mystr =~ /e.*fg/);
Is there anyone around who can reduce this to only one regexp?
The revolution of the world will not be stopped anytime soon!

Replies are listed 'Best First'.
Re^2: Regarding Regular Expressions
by pbeckingham (Parson) on Aug 17, 2004 at 13:15 UTC

    Solutions involving substitution are not what the OP wants. How about this:

    my @results = $mystr =~ /(efg)/g;
    Taken literally, "e followed by fg" is efg. If other characters may come between, try:
    my @results = $mystr =~ /(e.*?fg)/g;



    pbeckingham - typist, perishable vertebrate.
      Thats wrong, since the example has more 'fg' as 'e' so every hit starts at the first e and ends at x's 'fg'.
      $input = 'xxxxefghijklfghijklabcdefg'; __OUTPUT__ efg efghijklfg efghijklfghijklabcdefg
      Boris