in reply to Substitute problem

Try

s/(?<!_n)\@mail\.ab\.com/_n\@mail.ab.com/g;

The zero-width negative look-behind, (?<!_n) says only match if the @ sign is NOT preceded by the _n. Ie. if the address already has the '_n' it won't be modified.


Examine what is said, not who speaks.
"Efficiency is intelligent laziness." -David Dunham
"When I'm working on a problem, I never think about beauty. I think only how to solve the problem. But when I have finished, if the solution is not beautiful, I know it is wrong." -Richard Buckminster Fuller

Replies are listed 'Best First'.
Re: Re: Substitute problem
by Anonymous Monk on Jul 30, 2003 at 21:28 UTC
    Thanks to both of you!!!!

    You saved me hours (and probably days) of figuring this out! It works as it should on NT and my next step is to do it on my Unix and I assume it will work there also.

    The ?<!data is a reg expression that says dont match any of the data word? So I assume the ?< is a predecessor reg expression and the ! is the not part of the reg expression?

      Right. Sort of:)

      (?<!  ) is the negative look-behind assertion construct. You put the bit that you want to trigger failure in the gap, but it must be a simple, fixed width expression. You can't use a variable width thing in there.

      See perlre. Section Extended patterns for more information. (Theres actually not much more info there. See perlretut. Section "Looking ahead and looking behind" which does.


      Examine what is said, not who speaks.
      "Efficiency is intelligent laziness." -David Dunham
      "When I'm working on a problem, I never think about beauty. I think only how to solve the problem. But when I have finished, if the solution is not beautiful, I know it is wrong." -Richard Buckminster Fuller

        Thanks!!!