开发者

PERL + match exactly string(from left side) in line

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

E开发者_如何学运维xample of what not need to match:

a1234=  OLD
sss q1234=  OLD


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'!)


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜