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

时间:2017-08-01 08:09:28

标签: php regex preg-match

如果字符串或文本包含特定域,例如

,我想跳过并function updateXDiv(myDate) { if (lastZoomDate <= myDate) { document.getElementById('x-min').innerHTML = xAxis.scale().domain()[0]; document.getElementById('x-max').innerHTML = xAxis.scale().domain()[1]; } } 返回0
preg_match()

如果有$var="for see our post visit phyteachers.com |click now"; if(preg_match('(((https?|ftps?)\:\/\/)?((www([0-9]+)?)\.)?.*\.[a-zA-Z0-9](\/)?((?!.*phyteachers\b).*))','$var')==0){ echo "ok"; } http://phyteachers.comhttp://www.phyteachers.comhttps://www.phyteachers.comhttps://phyteachers.comwww.phyteachers.com,则返回phyteachers.com。< / p>

1 个答案:

答案 0 :(得分:1)

我的以下模式可能会有所改进,但它应该符合您的目的。

~(?:(?:ht|f)tps?:/{2})?(?:w{3}\d*\.)?(?:phyteachers\.com(*SKIP)(*FAIL)|\S+\.[a-z\d]+/?\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-z\d]+/?\S*             # see the demo, too involved to explain in limited space
)                                  # end non-capturing group