[英]Notepad++ regex to insert character every nth character from a starting position
How do you use regex to insert | 如何使用正则表达式插入| every two characters from a starting position to the end of the line? 从起始位置到行尾每两个字符?
Using regex on the following sample (tshark output of packet data), the regex inserts | 在以下示例中使用正则表达式(数据包数据的tshark输出),正则表达式将插入| after the first two characters and the next two characters, but does not apply the pattern to the rest of the line. 在前两个字符和后两个字符之后,但不会将模式应用于行的其余部分。 I think the issue is with a repeated pattern on the 2nd grouping (or lackthereof). 我认为问题在于第二分组的重复模式(或缺乏)。
Sample: 样品:
1478646603.255173000 10.10.10.1 0000000000000000000000
^(.{34})(..) replace with \1|\2| OR ^(.{34})(.*?(..)) replace with \1|\2
Produces this: 产生这个:
1478646603.255173000 10.10.10.1 00|00|000000000000000000
What I want is: 我想要的是:
1478646603.255173000 10.10.10.1 00|00|00|00|00|00|00|00|00|00|00
You may use 您可以使用
(?:\G(?!^)|^.{36})\K..(?!$)
and replace with $&|
并替换为$&|
. 。
Details : 详细资料 :
(?:\\G(?!^)|^.{36})
- matches the location at the end of the previous successful match (with \\G(?!^)
) or ( |
) the start of a line ( ^
) and the first 36 characters other than linebreak chars ( .{36}
) (?:\\G(?!^)|^.{36})
-匹配上一次成功匹配结束时的位置(使用\\G(?!^)
)或( |
)行的开头( ^
)以及除换行符( .{36}
)以外的前36个字符 \\K
- the match reset operator that discards the whole text matched so far \\K
匹配重置运算符,它丢弃到目前为止匹配的整个文本 ..
- any 2 chars other than linebreak chars ..
-任何2个字符不是断行字符等 (?!$)
- that are not at the end of the string. (?!$)
-不在字符串末尾。 The replacement pattern only contains the backreference to the whole match ( $&
) and a |
替换模式仅包含对整个匹配项( $&
)的反向引用和|
pipe symbol (a literal symbol in the replacement pattern). 管道符号(替换模式中的文字符号)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.