正则表达式-Tagmanager-筛选子目录的最佳方法

时间:2018-10-24 14:46:07

标签: regex

我正在尝试基于正则表达式为具有本地化语言的网站创建一个新的tagmanager视图过滤器。 URL上没有显示英文版本,但是对于本地化语言,我们添加/ es /或/ pt /,并且URL的结尾始终为英文版本。

我要显示的页面

https://example.com/demo
https://example.com/es/demo
https://example.com/pt/demo
https://example.com/de/demo
https://example.com/features
https://example.com/de/features
https://example.com/pt/features
https://example.com/es/features

我不想显示的页面

https://example.com/demo1231
https://example.com/demoabc
https://example.com/demo/asdas
https://example.com/features-1231
https://example.com/featuresasaa

欢迎咨询。

1 个答案:

答案 0 :(得分:1)

这是一个正则表达式,它将与您显示的示例匹配(不匹配的示例除外):

^https:\/\/example.com\/((es|pt|de)\/)?(demo|features)$

如果输入范围超过一行,则需要设置'multiline'选项。

正则表达式从行首开始,与文字字符串'https://example.com/'相匹配,然后由optional'es'或{{1 }},后跟'pt'。然后,它在'de'处检查字符串slash'demo'