Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > regular expresion, search replace

Reply
Thread Tools

regular expresion, search replace

 
 
ask8y@yahoo.com
Guest
Posts: n/a
 
      02-19-2013
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,
 
Reply With Quote
 
 
 
 
Jürgen Exner
Guest
Posts: n/a
 
      02-19-2013
http://www.velocityreviews.com/forums/(E-Mail Removed) 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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
need regular expression to replace part of result based on a search pattern Jimmy Java 13 07-25-2012 09:37 PM
Regular expression search and replace Jimmy Java 25 05-26-2010 06:33 PM
Search, Replace with Regular Expression tushar.n.patel@gmail.com ASP .Net 1 02-09-2005 10:09 PM
Search, Replace with Regular Expression lucky ASP .Net 0 02-09-2005 07:10 AM
regular expression search replace J. VerSchave Java 2 02-29-2004 08:08 PM



Advertisments