[英]Regex: Match everything except string
I've got the regex 我有正则表达式
^(.)+?domain\.com
which machtes 哪个大礼包
www.domain.com or
domain.com or
something.domain.com but
.domain.com too.
What I want is to "filter out" the possibility of ".domain.com". 我想要的是“过滤”“ .domain.com”的可能性。 It should match [something].domain.com and domain.com but NOT .domain.com.
它应该匹配[something] .domain.com和domain.com,但不匹配.domain.com。 (or ..domain.com).
(或..domain.com)。 It should be a valid subdomain.
它应该是有效的子域。 What would be the correct regex to get this done?
完成此操作的正确正则表达式是什么?
Updated question to clarify requirements. 更新了问题以阐明要求。
这种模式可以做到
^([^.]+\.)*domain\.com
Actually it will match otherdomain.com
too. 实际上,它也将匹配
otherdomain.com
。 A better approach might be to allow zero or one occurrences of non-dot+ dot: 更好的方法可能是允许零或一次出现非点+点:
^([^.]+\.)?domain.com$
As suggested in a comment, to allow many levels of subdomains, change ?
如评论中所建议,要允许多个级别的子域,请更改
?
to *
. 到
*
。
这将允许多个子域和域本身
^(.*\.)?domain.com&
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.