[tpm] Regex question

Uri Guttman uri at stemsystems.com
Tue Nov 6 11:30:41 PST 2007

>>>>> "EJ" == Emil Janev <ejanev at gmail.com> writes:

  EJ> Hi Indy,
  EJ> Instead of:

  EJ> while ($x =~ s//(^|$)foo.*?\n//gs) {1;}

  EJ> I tried:

  EJ> $x =~ s/(^|$)foo.*?\n//mgs;

the /s is bad there as it makes . match newline so that could run over a
line. even if it works, it is misleading as you don't want . to match

i don't know what the (^|$) is for. $ at the beginning of a regex makes
no sense and ^ will always match as it has /m set and there are
lines. so the |$ should never even be hit.

my version (untested) is this:



Uri Guttman  ------  uri at stemsystems.com  -------- http://www.stemsystems.com
--Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
Search or Offer Perl Jobs  ----------------------------  http://jobs.perl.org

More information about the toronto-pm mailing list