在记事本++中的某些标签之间用逗号替换空格 [英] Replace whitespace with comma between certain tags in notepad++
本文介绍了在记事本++中的某些标签之间用逗号替换空格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试在记事本++中编写一个正则表达式,它将包含在 2 个标签之间的所有空格替换为逗号.
I'm trying to write a regex in notepad++ that takes all whitespaces contained between 2 tags and replace them with comma.
所以基本上,如果我有这个输入:
So basically, if I have this input:
<foo>bar bar bar</foo>
<tag>bar bar bar</tag>
而且我只想替换 foo 标签内的空格以获得结果:
And I want to replace whitespaces only inside foo tags to get a resut:
<foo>bar,bar,bar</foo>
<tag>bar bar bar</tag>
匹配 foo 之间的所有内容相当简单:
Matching everything between foo is fairly straightforward:
(?<=(<foo>))(.*)(?=(<\/foo>))
但是搜索 \s 不起作用:
But searching for \s doesn't work:
(?<=(<foo>))(\s)(?=(<\/foo>))
推荐答案
由于您想替换没有子标签的标签内的空格,也没有相同的嵌套标签,您可以使用
Since you want to replace the spaces inside tags that has no children, nor the same nested tags, you may use
(?:\G(?!^)|<foo>)[^\s<]*\K\s+
参见正则表达式演示,替换为,
.
详情:
(?:\G(?!^)|
- 前一个成功匹配的结尾或者) [^\s<]*
- 除空格和<
之外的零个或多个符号\K
- 省略目前匹配的文本\s+
- 1 个或多个空格.
(?:\G(?!^)|<foo>)
- either the end of the previous successful match or<foo>
[^\s<]*
- zero or more symbols other than whitespace and<
\K
- omit the text matched so far\s+
- 1 or more whitespaces.
这篇关于在记事本++中的某些标签之间用逗号替换空格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文