regular expresion, search replace

A

ask8y

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,
 
J

Jürgen Exner

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
 

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. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,994
Messages
2,570,223
Members
46,810
Latest member
Kassie0918

Latest Threads

Top