javascript Reg Exp to match specific domain name

前端 未结 6 2107
小鲜肉
小鲜肉 2021-01-12 09:34

I have been trying to make a Reg Exp to match the URL with specific domain name.

So if i want to check if this url is from example.com what reg exp should be the bes

6条回答
  •  梦毁少年i
    2021-01-12 10:14

    There are cases where the domain you're looking for could actually be found in the query section but not in the domain section: https://www.google.com/q=www.example.com

    This answer would treat that case better.
    See this example on regex101.

提交回复
热议问题