in reply to replacing email id using regex

shmem has given you and answer using look around assertions but if you were to do this using regex captures you have to disambiguate the capture using braces. Your code is trying to replace with the variable $1something which, unsurprisingly, doesn't do what you want. Try something like

use strict; use warnings; $_ = q{aaa@z.com bbb@z.com ccc@z.com}; print qq{$_\n}; s{([^@]+@)[^.]+}{${1}something}g; print qq{$_\n};

which produces

aaa@z.com bbb@z.com ccc@z.com aaa@something.com bbb@something.com ccc@something.com

Cheers,

JohnGG

Update: shmem has pointed out that I'm completely wide of the mark here and that $1 and friends are never ambiguous.

Replies are listed 'Best First'.
Re^2: replacing email id using regex
by shmem (Chancellor) on Jan 02, 2007 at 11:06 UTC

    No, $1something isn't ambiguous, $<digit> variables never are:

    $ perl -le '$_ = "aaa\@z.com bbb\@z.com ccc\@z.com"; s/(.+?\@)(.+?\.)( +.+?)/$1something.$3/g;print' aaa@something.com bbb@something.com ccc@something.com

    In fact, a variable $1something is illegal:

    $ perl -e '$1something' Bareword found where operator expected at -e line 1, near "$1something +" (Missing operator before something?) syntax error at -e line 1, next token ??? Execution of -e aborted due to compilation errors.

    --shmem

    _($_=" "x(1<<5)."?\n".q·/)Oo.  G°\        /
                                  /\_¯/(q    /
    ----------------------------  \__(m.====·.(_("always off the crowd"))."·
    ");sub _{s./.($e="'Itrs `mnsgdq Gdbj O`qkdq")=~y/"-y/#-z/;$e.e && print}
      I didn't know that, thank you. You learn something new literally every day in the Monastery.

      Cheers,

      JohnGG