如果在正则表达式中存在特定的域,如何跳过并说不匹配?
我想跳过和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](\/)?((?!.*phyteachers\b).*))','$var')==0){
echo "ok";
}
如果http://phyteachers.com
或http://www.phyteachers.com
或https://www.phyteachers.com
或https://phyteachers.com
或www.phyteachers.com
或phyteachers.com
然后返回0
特定领域。
我的下列模式可能会稍微改进一点,但它应该可以满足您的目的。
~(?:(?: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
非常好!但它不捕获其他链接子类别https://regex101.com/r/iZ9HRQ/3 –
@MohammadrezaTaheri我有轻微改善我的模式,并添加了解释。请在您的项目中使用我更新的模式。 – mickmackusa
对不起,子域仍然不能正常工作 –
难道你不能简化通过使用'strpos'? http://php.net/manual/ro/function.strpos.php –
我该怎么做? –
你能否写下代码? –