正则表达式替换

时间:2016-12-02 11:11:49

标签: regex perl

我有一个文件,并且该单词出现在该行的中间,基于从行的开头到模式匹配需要替换的单词。

示例行:

the browser separates off the name/value pairs and other information which is sent in the header and puts it in

在这里,我们需要找到单词other并从行的开头替换为other }的单词the

提前致谢。

1 个答案:

答案 0 :(得分:0)

你可能期待这个:

use strict;
use warnings;

while(<DATA>) {  $_=~s/^((?:(?!other).)*)other//i;  print $_;  }

__DATA__
the browser separates off the name/value pairs and other information which is sent in the header and puts it in

输出:

 information which is sent in the header and puts it in