tags:

views:

70

answers:

2

Hi all

I have problem with the following perl command How to match all "1234" strings in file, but if some characters jointed before "1234" then it will not match, my problem is: if the string "1234" in the middle of the line then it not match why?

The perl command:

perl  -pe 's/OLD/NEW/ if /^1234/' file

Example of what need to match:

a ass 1234= OLD
bbb ddd 1234= OLD
 1234= OLD

Example of what not need to match:

a1234=  OLD
sss q1234=  OLD
A: 

The ^ matches "the beginning of the line". Try removing that character in the regular expression. Replace it with a space character.

Marcus Adams
+2  A: 

Change the ^ to \b. That will match only if the 1234 is the start of a word. (If necessary, see perldoc perlre for more information on what constitutes a 'word'!)

psmears
I have problem when the parameter is *.55555then its not matched??
yael
You have edited the question substantially from the previous one, and now everyone's answers don't make sense... I think it would be better to revert your question to how it was before, then ask a new question with the new problem... if you post the link here, I'm sure everyone who's looked at this question will take a look at that one :-)
psmears
I reverted it back to the previous question since yael has reposted the newer question. http://stackoverflow.com/questions/3110329/perl-how-to-match-special-characters/3110368#3110368
Mark Byers