我想通过替换来进行解析pagina-EN
。aborde.html
我希望使用正则表达式进行替换,而不是使用常规的查找/替换方式。
所以我有:
<link rel="canonical" href="https://MyWebsite.com/en/aborde.html" />
并添加另一个 HTML 标签:
<link rel="alternate" hreflang="x-default" href="https://MyWebsite.com/en/pagina-EN.html" />
<link rel="alternate" hreflang="sl" href="https://MyWebsite.com/sl/pagina-EN.html" />
<link rel="alternate" hreflang="bg" href="https://MyWebsite.com/bg/pagina-EN.html" />
<link rel="alternate" hreflang="sk" href="https://MyWebsite.com/sk/pagina-EN.html" />
<link rel="alternate" hreflang="uk" href="https://MyWebsite.com/uk/pagina-EN.html" />
输出应为:
<link rel="alternate" hreflang="x-default" href="https://MyWebsite.com/en/aborde.html" />
<link rel="alternate" hreflang="sl" href="https://MyWebsite.com/sl/aborde.html" />
<link rel="alternate" hreflang="bg" href="https://MyWebsite.com/bg/aborde.html" />
<link rel="alternate" hreflang="sk" href="https://MyWebsite.com/sk/aborde.html" />
<link rel="alternate" hreflang="uk" href="https://MyWebsite.com/uk/aborde.html" />
我的解决方案:
搜索:(?s)<link rel="canonical" href="(.*?)" />.*?<link rel="alternate" hreflang=".*?".*?\K href="(.*?)//(.*?)/(.*?) />
替换为: \thref="\1" />
- 查看 环绕
- 查看 正则表达式
- 查看
. matches newline
- Replace all