我有一个以下的RegExp
[-a-zA-Z0-9@:%._\+~#=]{2,256}\.[a-z]{2,6}\b([-a-zA-Z0-9@:%_\+.~#?&//=][A-Z0-9]{3,10})
它将域及其子域匹配,并且还需要在地址中提供参数,但是,我希望能够从匹配中排除某些子域。我尝试使用负面Lookhead来实现这一目标,但没有成功。
^((?!(domain|orsubdomain)).)*$
应与模式匹配的文本:
nicesite.abc.com/abcs
nicesite.com/abcs
并且不应该匹配:
niceDomain.com/abcs
hello.orsubdomain.com/abcs
任何帮助将非常感激。
试试这个:
\b(?!.*\.?(domain|orsubdomain)\/?.*)(?:[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?\.)+[a-z0-9][a-z0-9-]
它起作用,至少在你的例子中!