我有一组可能的 URL:
www.example.com
www.example.user.dev
subdomain.example.com
subdomain.example.user.dev
www.en.example.com
www.en.example.user.dev
subdomain.en.example.com
subdomain.en.example.user.dev
subdomain
可以是任何单词。
我需要一个正则表达式来查找所有不以 www
开头的 URL,因此结果集应该是:
subdomain.example.com
subdomain.example.user.dev
subdomain.en.example.com
subdomain.en.example.user.dev
我有正则表达式 /[a-z]+\.(en\.|)example\.(com|[a-z]+\.dev)/i
我需要将其修改为 mathc仅限不以 www
开头的 URL。是否可以仅使用正则表达式来解决,或者我是否需要在代码中编写一些逻辑?
UPD:
正则表达式 /\b(?!www\b)[a-z]+\.(en\.|)example\.(com|[a-z]+\.dev)/i
可以正常工作没有 .en
部分的 URL,但在具有 .en
的 URL 上失败。
最佳答案
给你:
^(?!www\.)((([a-z]{4,})|([a-z]{2}))\.(en\.|)example\.(com|[a-z]+\.dev))
关于javascript - 匹配 URL 的正则表达式以子域开头,但不是 "www",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33803990/