in reply to A regex that does this, but not that?

$var =~ s[\bt(?!est).*?t\b\s*][]g;

Update: sauoq's right. I omitted a \b.

perl> $var = "thought testament test tot 1 2 3 tesset"; perl> $var =~ s[\bt(?!est\b).*?t\b\s*][]g; print $var; test 1 2 3

Examine what is said, not who speaks.
"Efficiency is intelligent laziness." -David Dunham
"Think for yourself!" - Abigail
Hooray!
Wanted!

Replies are listed 'Best First'.
Re: Re: A regex that does this, but not that?
by sauoq (Abbot) on Nov 15, 2003 at 00:00 UTC

    But, if $var contained "testament", for example, that would fail.

    -sauoq
    "My two cents aren't worth a dime.";
    

      Yep!. Needs an extra \b.


      Examine what is said, not who speaks.
      "Efficiency is intelligent laziness." -David Dunham
      "Think for yourself!" - Abigail
      Hooray!
      Wanted!