如果正则表达式中存在特定域,如何跳过并说不匹配?



>我想跳过并preg_match()返回 0 例如,如果字符串或文本包含特定域

$var="for see our post visit phyteachers.com |click now";
if(preg_match('(((https?|ftps?)://)?((www([0-9]+)?).)?.*.[a-zA-Z0-9](/)?((?!.*phyteachersb).*))','$var')==0){
echo "ok";
}

如果有http://phyteachers.comhttp://www.phyteachers.comhttps://www.phyteachers.comhttps://phyteachers.comwww.phyteachers.comphyteachers.com则返回0

我的以下模式可能可以稍微改进一下,但它应该可以满足您的目的。

~(?:(?:ht|f)tps?:/{2})?(?:w{3}d*.)?(?:phyteachers.com(*SKIP)(*FAIL)|S+.[a-zd]+/?S*)~

https://regex101.com/r/iZ9HRQ/6

有关我的模式组件的正式术语,请参阅演示链接。 否则,我将提供一个非正式的解释...

(?:                 # start optional non-capturing group
(?:ht|f)tps?    # match http, https, ftp, ftps
:/{2}           # match colon then two slashes
)?                  # end optional group (none of this HAS to exist)
(?:                 # start optional non-capturing group
w{3}d*.       # match www then zero or more digits, then optiona
)?                  # end optional group
(?:                                # start non-capturing group
phyteachers.com(*SKIP)(*FAIL) # abort match if found 
|                              # or
S+.[a-zd]+/?S*             # see the demo, too involved to explain in limited space
)                                  # end non-capturing group

最新更新