RegEx多个捕获组替换为一个字符串
我有一串数据...
"123456712J456","D","TEST1~TEST2~TEST3~TEST4~TEST5"
我想采取以下字符串,并使5个字符串。
"123456712J456","D","TEST1"
"123456712J456","D","TEST2"
"123456712J456","D","TEST3"
"123456712J456","D","TEST4"
"123456712J456","D","TEST5"
我目前有以下正则表达式...
//In a program like Textpad
<FIND> "(.{13})","D","([^~]*)~(.*)
<REPLACE> "1","D","2"n"1","D","3
//On the regex101 site
"(.{13})","D","([^~]*)~(.*)
现在,如果我运行这5次,它会正常工作。 问题是有未知的行数。 例如...
"123456712J456","D","TEST1~TEST2~TEST3~TEST4~TEST5"
"123456712J457","D","TEST1~TEST2~TEST3"
"123456712J458","D","TEST1~TEST2"
"123456712J459","D","TEST1~TEST2~TEST3~TEST4"
我希望能够使用MULTI捕获组来完成这项工作。 我发现这个页面谈论重复捕捉组和捕捉重复组之间的常见错误。 我需要捕捉一个重复的组。 出于某种原因,我只是无法让我的工作正确。 其他人有想法?
资源:
试试这个,看demo.Just俱乐部match1
和rest of the matches
。
http://regex101.com/r/yR3mM3/17
正则表达式:
(.*,)|([^"~]+)
例:
"1234567123456","T","TEST1~TEST2~TEST3~TEST4~TEST5"
结果:
MATCH 1
1. [0-20] `"1234567123456","T",`
MATCH 2
2. [21-26] `TEST1`
MATCH 3
2. [27-32] `TEST2`
MATCH 4
2. [33-38] `TEST3`
MATCH 5
2. [39-44] `TEST4`
MATCH 6
2. [45-50] `TEST5`
链接地址: http://www.djcxy.com/p/74843.html
上一篇: RegEx multiple capture groups replaced in a string
下一篇: Repeated capturing groups in regex when only last match is allowed (workaround)