用于匹配 URL 并插入目录的正则表达式
我想使用正则表达式来匹配以下内容:
http://www.test.com/example/sometext/
然后重定向到:
http://www.test.com/uk/example/sometext/
其中 'example
' 不在保留字列表中,例如 _images
、_lib
、_css
等。
I would like to use regex to match the following:
http://www.test.com/example/sometext/
and then redirect to:
http://www.test.com/uk/example/sometext/
where 'example
' is not in a list of reserved words, like _images
, _lib
, _css
, etc.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用否定的前瞻:
并替换为
Broken down,有趣的是:
(?!someregex)
= 否定的前瞻 - 即断言以下输入与someregex
不匹配(_images|_lib|_css)
= 正则表达式OR
逻辑的语法,仅使用文字[^/]+
= 某些字符t 斜线Use a negative look ahead:
And replace with
Broken down, the juicy buts are:
(?!someregex)
= a negative lookahead - ie assert the following input does not matchsomeregex
(_images|_lib|_css)
= the syntax for regexOR
logic, just using literals[^/]+
= some characters that aren't a slash