regular expresion, search replace

Discussion in 'Perl Misc' started by ask8y@yahoo.com, Feb 19, 2013.

  1. Guest

    I would search a variable in a script, and change the value. For example for following line

    export NAME=FOO_1 #something

    Change it to

    export NAME=BAR_1 #something

    I have following two rules. I expect 1) work. But 1) did not yield a match. 2) did. Can some one explain?

    1) s/NAME=[a-zA-Z]\w*$/NAME=BAR_1/

    2) s/NAME=[a-zA-Z]\w*/NAME=BAR_1/


    Thanks in advance,
    , Feb 19, 2013
    #1
    1. Advertising

  2. wrote:
    >I would search a variable in a script, and change the value. For example for following line
    >
    >export NAME=FOO_1 #something
    >
    >Change it to
    >
    >export NAME=BAR_1 #something
    >
    >I have following two rules. I expect 1) work. But 1) did not yield a match. 2) did. Can some one explain?


    Lert's translate them into plain English

    >1) s/NAME=[a-zA-Z]\w*$/NAME=BAR_1/


    "NAME="
    followed by any single letter ==> "F"
    followed by any number of "word characters" ==> "OO_1"
    followed by the end of the line ==> cannot match because there is more
    text between the current position and the end of the line

    >2) s/NAME=[a-zA-Z]\w*/NAME=BAR_1/


    "NAME="
    followed by any single letter ==> "F"
    followed by any number of "word characters" ==> "OO_1"
    No other requirements, so this obviously matches.

    jue
    Jürgen Exner, Feb 19, 2013
    #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. Andy
    Replies:
    5
    Views:
    474
    Ron Natalie
    Jan 23, 2005
  2. Replies:
    0
    Views:
    454
  3. Matt White

    Regular Expresion Needed

    Matt White, Jun 19, 2007, in forum: Ruby
    Replies:
    2
    Views:
    88
    Bertram Scharpf
    Jun 19, 2007
  4. Filipe

    Regular Expresion Error?

    Filipe, Sep 29, 2007, in forum: Ruby
    Replies:
    4
    Views:
    104
    Filipe
    Oct 5, 2007
  5. Jose Luis

    Newbie: Regular expresion

    Jose Luis, Sep 18, 2009, in forum: Perl Misc
    Replies:
    4
    Views:
    84
    Steve C
    Sep 18, 2009
Loading...

Share This Page