我需要一个匹配的正则表达式:
http://example.com/foo
http://example.com/foo/
http://example.com/foo/bar
但不是:
http://example.com/foobar
使用
http://example.com/foo/?
匹配三种类型,但匹配 /foobar
也是我不想要的。我应该在正则表达式中添加什么以不匹配 /foobar
?
最佳答案
试试这个:
^http://example\.com/foo(?:/.*)?$
关于正则表达式匹配 URL 中的单词,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8987823/