如何创建不包含字符串“umbraco”且不以/结尾的正则表达式
这是我目前所拥有的,但我无法使其完全正常工作,我们将不胜感激。
(?!umbraco)(?![/]$)
测试字符串是:
- > http://www.domain.com/umbraco/login.aspx - 不应该匹配
- > http://www.domain.com/pages/1/ - 不应该匹配
- > http://www.domain.com/pages/1 - 应该匹配
最佳答案
应该是这个正则表达式:
^(?!.*?umbraco).*?[^\/]$
在线演示:http://regex101.com/r/lM0cS9
解释:
^ assert position at start of a line
(?!.*?umbraco) Negative Lookahead - Assert that it is impossible to match the regex below
.*? matches any character (except newline)
Quantifier: Between zero and unlimited times, as few times as possible, expanding as needed
umbraco matches the characters umbraco literally (case sensitive)
.*? matches any character (except newline)
Quantifier: Between zero and unlimited times, as few times as possible, expanding as needed
[^\/] match a single character not present in the list below
\/ matches the character / literally
$ assert position at end of a line
关于javascript - 正则表达式 - 不包含字符串且不以/结尾,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21751507/