你好,新年快乐!
处理超过 2000 个 .html 文件时遇到一点问题。我需要从下一个特定标签中选择所有空格,并用一个空格替换。
<p class="test_formal"> This is my text <em>and all of this</em> I have to go home .</p>
我的正则表达式不太好:(
搜索:(?s)(?:\G)|<p class="text_formal">).*?|.*(?=</p>)|+\h
替换为:(Leave one space)
答案1
- Ctrl+H
- 找什么:
(?:^<p class="text_formal">|\G)\K\s*(\S+)
- 替换为:
$1
# 一个空格然后 $1 - 检查环绕
- 检查正则表达式
- Replace all
解释:
(?: # start non capture group
^ # beginning of line
<p class="text_formal"> # literally
| # OR
\G # restart from last match position
) # end group
\K # forget all we have seen until this position
\s* # 0 or more spaces
(\S+) # group 1, 1 or more any character that is not a space
给定示例的结果:
<p class="test_formal"> This is my text <em>and all of this</em> I have to go home .</p>
答案2
- 选择要更改的部分
- Ctrl+H
- 查找内容:(
+
空格和加号) - 替换为:(
仅需空格)
- 勾选
In selection
(或按 Alt+I) - 单击
Replace all
按钮(或按 Alt+A)
就这样 :)