正则表达式搜索组默认值
我需要从 Google Analytics 内容组的路径中提取语言。 url 的格式为 /:language/rest_of_the_path
,如果缺少 /:language
部分,则为默认语言(例如 en
)
我的正则表达式如下,
^/?(en|de|fr|)/
除了默认替换空白语言之外,它工作正常。
这只能通过正则表达式来实现吗?
I need to extract language from the path for Google Analytics Content Group. The format of the url is /:language/rest_of_the_path
, if the /:language
part is missing it is default language (ex. en
)
My regex is follwing
^/?(en|de|fr|)/
It works fine exept for the default substitution for the blank language.
Can this be achived by regex only?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
搜索此模式 ^/(?!en/|de/|fr/)
并替换为 /en$0
它使用负向前瞻,并且仅当在 url 开头找不到可识别的语言时才进行替换
Search for this pattern ^/(?!en/|de/|fr/)
And replace with /en$0
It uses negative lookahead and it replaces only when it doesn't find a recognized language at the beginning of the url