简体   繁体   English

使用记事本++正则表达式查找并替换分隔数据文件中的第 n 个元素

[英]Find and replace the nth element in a delimited data file using notepad++ regex

Given a delimited text file like below(separated by |), I need to find the nth element and replace it with new value.给定一个如下所示的分隔文本文件(由 | 分隔),我需要找到第 n 个元素并将其替换为新值。

1|ppp|168|.20||3|00100|RNRBT5|VS08|RCK|150W|TE21|TE21|||||||RA|CXXXXXX|29|30|290|300|1|X|Q8|.2002||00003|00100|RN|VS|RCKR|150W|TE21|TE21|||||||RM|CXXXXXX|29|30|90|300
1|ppp|168|.20||3|00100|RNRBT5|VS08|RCK|150W|TE21|TE21|||||||RA|CXXXXXX|29|30|290|300|1|X|Q8|.2002||00003|00100|RN|VS|RCKR|150W|TE21|TE21|||||||RM|CXXXXXX|29|30|90|300
1|ppp|168|.20||3|00100|RNRBT5|VS08|RCK|150W|TE21|TE21|||||||RA|CXXXXXX|29|30|290|300|1|X|Q8|.2002||00003|00100|RN|VS|RCKR|150W|TE21|TE21|||||||RM|CXXXXXX|29|30|90|300
1|ppp|168|.20||3|00100|RNRBT5|VS08|RCK|150W|TE21|TE21|||||||RA|CXXXXXX|29|30|290|300|1|X|Q8|.2002||00003|00100|RN|VS|RCKR|150W|TE21|TE21|||||||RM|CXXXXXX|29|30|90|300

example replacement requirement are like below:示例更换要求如下:

find the 4th element ".20" at 1st line and replace it with a velue like "jko"
find the 6th element "3" at 1st line and replace it with a velue like "uo"
find the 10th element "RCK" at 2nd line and replace it with a velue like "ko"

Solution I have tried我试过的解决方案

find with Regex(try to find and replace the 4th element) ^(?:[^\|]*\|){3}([^\|]*) with this match result is使用正则表达式查找(尝试查找并替换第 4 个元素) ^(?:[^\|]*\|){3}([^\|]*)与此匹配结果是

1|ppp|168|.20

and the group 1 result is .20第 1 组的结果是.20

I stuck here because I can't find a way to replace only the group 1 result我被困在这里是因为我找不到只替换第 1 组结果的方法

I hope you meant this.我希望你是这个意思。
Find what: (^.*?\.)20(\|\|)3(.*?)rck查找内容: (^.*?\.)20(\|\|)3(.*?)rck
Replace with: $1jko$2uo$3ko替换为: $1jko$2uo$3ko

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM