please explain to me

Discussion in 'Perl Misc' started by robertchen117@gmail.com, Feb 2, 2007.

  1. Guest

    please explain this to me:

    s/\s+(!\W+)/$1 /;


    s is replace, expecially (!\W+)
    , Feb 2, 2007
    #1
    1. Advertising

  2. Alex Guest

    wrote:
    > please explain this to me:
    >
    > s/\s+(!\W+)/$1 /;
    >
    >
    > s is replace, expecially (!\W+)


    perldoc perlre
    It's an exclamation mark. AFAIK it doesn't have any special meanin, at
    least in this context.

    So the regexp replaces one or more whitespace characters followed by one
    or more non-alphabetic characters beginning with (and including) an
    exclamation mark.

    For illustration, try using putting parenthesis around the captured
    variable like so (dropping the last space):

    perl -ane 's/\s+(!\W+)/($1)/;print'
    input:
    !"#&%asf
    !/(%df
    !"#¡è%asdf
    #¡è%&asdf
    output:
    (!"#¡è%)asf
    (!/(%)df
    !"#¡è%asdf
    #¡è%&asdf

    Note the lack of a space on the third line, and the lack of an
    exclamation mark on the fourth line. I guess the ! in the regexp might
    have confused you into thinking it to be the NOT-operator?

    HTH

    --
    Alex
    e-mail: Domain is iki dot fi. Local-part is alext.
    local-part at domain
    Alex, Feb 2, 2007
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. suzy
    Replies:
    3
    Views:
    442
  2. BluDog

    Can Someone Please Explain...

    BluDog, Oct 4, 2004, in forum: ASP .Net
    Replies:
    4
    Views:
    476
    BluDog
    Oct 5, 2004
  3. Alan Silver
    Replies:
    1
    Views:
    481
    Alan Silver
    Jun 28, 2005
  4. KK
    Replies:
    2
    Views:
    557
    Big Brian
    Oct 14, 2003
  5. Kaye Ng
    Replies:
    8
    Views:
    176
    Josh Cheek
    Jun 8, 2010
Loading...

Share This Page