Next Regular Expression Mastery 71

Repeated Matching: /g

        while ("I like pie" =~ /\w+/ g) {
          print "<$&>\n";
        }
        <I>
        <like>
        <pie>
        my $s = "I like pie";
        for ($i = 0; $i < length($s); $i += 2) {
          pos($s) = $i;
          $s =~ /\w*/ g;
          print "<$&>\n";
        }
        <I>
        <like>
        <ke>
        <>
        <ie>


Next Copyright © 2002 M. J. Dominus