2

我有一个包含数千行的文件,其中包含逗号分隔的列。

'one',2,'three','hello','xyz',5,'hello','mnr','hello','axi'
'onae',2,'tree','hello','xyz',6,'hello','mnr','hello','asd'
'onee',2,'xdsa','hello','xyz',5,'hello','mnr','hello','aew'
'owne',2,'thr','hello','xyz',3,'hello','mnr','hello','az'
'ocne',2,'tee','hello','xyz',5,'hello','mnr','hello','zse'
'owne',2,'tre','hello','xyz',2,'hello','mnr','hello','aai'

每行中的三列包含单词“hello”的值。

如何使用 Textpad 中的正则表达式在每行中将第二次出现的单词“hello”替换为数字 0,从而使这些行变为:

'one',2,'three','hello','xyz',5,0,'mnr','hello','axi'
'onae',2,'tree','hello','xyz',6,0,'mnr','hello','asd'
'onee',2,'xdsa','hello','xyz',5,0,'mnr','hello','aew'
'owne',2,'thr','hello','xyz',3,0,'mnr','hello','az'
'ocne',2,'tee','hello','xyz',5,0,'mnr','hello','zse'
'owne',2,'tre','hello','xyz',2,0,'mnr','hello','aai'   
4

2 回答 2

1

使用此 regx 进行搜索:

(.*?'hello'.*?),'hello',(.*)

并替换使用:

$1,0,$2

确保DOTALL(点匹配换行符)选项已关闭。

正则表达式演示

于 2015-10-14T22:22:47.210 回答
0

我投票赞成 anubhava 的解决方案,因为这让我非常接近解决方案。

找到这个:

^(.*?'hello'.*?),'hello',

替换为:

$1,0,
于 2015-10-23T23:18:47.750 回答