![正则表达式:在特定元标记中的单词之间添加逗号](https://linux22.com/image/1616813/%E6%AD%A3%E5%88%99%E8%A1%A8%E8%BE%BE%E5%BC%8F%EF%BC%9A%E5%9C%A8%E7%89%B9%E5%AE%9A%E5%85%83%E6%A0%87%E8%AE%B0%E4%B8%AD%E7%9A%84%E5%8D%95%E8%AF%8D%E4%B9%8B%E9%97%B4%E6%B7%BB%E5%8A%A0%E9%80%97%E5%8F%B7.png)
我有这个元标签
<meta name="keywords" content="Doing well is a great thing"/>
必须成为:
<meta name="keywords" content="doing, well, is, a, great, thing"/>
我尝试了这样的方法,但没有效果:
搜索:(<([^<meta name="keywords" content=>]+)>(.*?))
替换为:/1/2,
谁能帮我?
答案1
- Ctrl+H
- 找什么:
(?:<meta name="keywords" content="|\G)\w+\K\h+
- 替换为:
,
#逗号和空格 - 查看 环绕
- 查看 正则表达式
- Replace all
解释:
(?: # non capture group
<meta name="keywords" content=" # literally
| # OR
\G # restart from last match position
) # end group
\w+ # 1 or more word character
\K # forget all we have seen until this position
\h+ # 1 or more horizontal spaces
截图(之前):
截图(之后):