2

我有这条线来阻止像ad.somedomain.tld这样的广告主机名, 但它似乎阻止了像下载、上传等这样的主机名。

([\w.-]+\.)?ad\.[^/]+/?

什么是正确的语法,谢谢

4

1 回答 1

2

演示正则表达式101

正则表达式

\b(?:.?)ad(?:.?)\b

描述

\b Word boundary: match in between (^\w|\w$|\W\w|\w\W)
(?:.?) Non-capturing Group 
    . 0 to 1 times [greedy] Any character (except newline)
ad Literal ad
(?:.?) Non-capturing Group 
    . 0 to 1 times [greedy] Any character (except newline)
\b Word boundary: match in between (^\w|\w$|\W\w|\w\W)

可视化(由debuggex提供)

正则表达式可视化

于 2013-08-19T03:24:04.577 回答