doudou3716
doudou3716
采纳率0%
2019-03-26 23:13

RegEx从匹配中排除子域

已采纳

I have a below RegExp

[-a-zA-Z0-9@:%._\+~#=]{2,256}\.[a-z]{2,6}\b([-a-zA-Z0-9@:%_\+.~#?&//=][A-Z0-9]{3,10})

It matches domain along with its subdomain and parameters are also needed to be provided in an address, however, I want to be able to exclude some subdomains from matching. I've tried using negative Lookhead in order to achieve this, but without success.

^((?!(domain|orsubdomain)).)*$

Texts which should match the pattern:

nicesite.abc.com/abcs

nicesite.com/abcs

and shouldn't match:

niceDomain.com/abcs

hello.orsubdomain.com/abcs

Any help would be much appreciated.

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

1条回答

  • drqyxkzbs21968684 drqyxkzbs21968684 2年前

    Try this:

    \b(?!.*\.?(domain|orsubdomain)\/?.*)(?:[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?\.)+[a-z0-9][a-z0-9-]
    

    It works, at least with your examples!

    点赞 评论 复制链接分享

相关推荐