regular expresion, search replace

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

  1. ask8y

    ask8y 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,
     
    ask8y, Feb 19, 2013
    #1
    1. Advertisements

  2. Lert's translate them into plain English
    "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
    "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. Advertisements

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.