REGEXP常规/递归查找/替换在记事本++
如何将一些特定格式定义的字符串分开:
[length namevalue field]name=value[length namevalue field]name=value[length namevalue field]name=value[length namevalue field]name=value
在记事本++中的查找/替换时,二对名称=用白空间替换[长度名称value字段]的find/repens -regex? 主要问题与简单\ d {4}搜索不起作用的数字值有关。
例如。
输入:
0010name=mario0013surname=rossi0006age=180006phone=0014address=street
0013name=marianna0013surname=rossi0006age=210006phone=0015address=street1
0003name=pia0015surname=rossini0005age=30017phone=+39221122330020address=streetstreet
输出:
name=mario surname=rossi age=18 phone= address=street
name=mario surname=rossi age=18 phone= address=street
name=marianna surname=rossi age=21 phone= address=street1
name=pia surname=rossini age=3 phone=+3922112233 address=streetstreet
How to split some strings defined in a specific format:
[length namevalue field]name=value[length namevalue field]name=value[length namevalue field]name=value[length namevalue field]name=value
Is it possible with a Find/Replace regex in Notepad++ isolate the pair name=value replacing [length namevalue field] with a white space?
The main problem is related to numeric value where a simple \d{4} search doesn't work.
Eg.
INPUT:
0010name=mario0013surname=rossi0006age=180006phone=0014address=street
0013name=marianna0013surname=rossi0006age=210006phone=0015address=street1
0003name=pia0015surname=rossini0005age=30017phone=+39221122330020address=streetstreet
OUTPUT:
name=mario surname=rossi age=18 phone= address=street
name=mario surname=rossi age=18 phone= address=street
name=marianna surname=rossi age=21 phone= address=street1
name=pia surname=rossini age=3 phone=+3922112233 address=streetstreet
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用
regex demo 。
模式匹配
\ d {4}
- 四位数(?= [:alpha:]] \ w*=)\ w*=)
- ,它们紧随其后的是一封信,然后任何零或多个字char随后紧随当前位置右侧的=
char。(?= [^\ w \ d] \ w*=)
- 紧随其后的是字母或下划线,然后任何零或更多单词chars随后遵循= CHAR立即位于当前位置的右侧。
在记事本++中,如果要在行开始时删除匹配项,并用其他任何地方替换为空间,则可以用
(?1:)
替换。上面解释的模式,\ d {4}(?= [[:alpha:]] \ w*=)
,匹配, 捕获在第1组中,在行的开头(^
),并且只是在其他任何地方匹配((?1)
递归组1模式,以免重复它)。(?1:)
替换意味着如果组1匹配,我们用空字符串替换,否则,我们替换为空间。请参阅演示屏幕截图:
You can use
See the regex demo.
The patterns match
\d{4}
- four digits(?=[[:alpha:]]\w*=)
- that are immediately followed with a letter and then any zero or more word chars followed with a=
char immediately to the right of the current position.(?=[^\W\d]\w*=)
- that are immediately followed with a letter or an underscore and then any zero or more word chars followed with a=
char immediately to the right of the current position.In Notepad++, if you want to remove the match at the start of the line and replace with space anywhere else, you can use
and replace with
(?1: )
. The above explained pattern,\d{4}(?=[[:alpha:]]\w*=)
, is matched and captured into Group 1 if it is at the start of a line (^
), and just matched anywhere else ((?1)
recurses the Group 1 pattern, so as not to repeat it). The(?1: )
replacement means we replace with empty string if Group 1 matched, else, we replace with a space.See the demo screenshot: