gpt4 book ai didi

php - 在 PHP 中使用 Gruber 的正则表达式进行网址匹配

转载 作者:可可西里 更新时间:2023-11-01 13:59:00 27 4
gpt4 key购买 nike

如何获取提到的正则表达式 in this article在 php 中使用 preg_match?

<?php
preg_match("\b(([\w-]+://?|www[.])[^\s()<>]+(?:\([\w\d]+\)|([^[:punct:]\s]|/)))/i", $text, $matches);
print_r($matches);
?>

使用上面的代码我得到以下错误:

Warning: preg_match() [function.preg-match]: Delimiter must not be alphanumeric or backslash...

最佳答案

试试这个:

preg_match("#\b(([\w-]+://?|www[.])[^\s()<>]+(?:\([\w\d]+\)|([^[:punct:]\s]|/)))#i", $text, $matches);

您缺少正则表达式分隔符(通常是 /,但在这里使用 # 因为它对 URL 更方便)

关于php - 在 PHP 中使用 Gruber 的正则表达式进行网址匹配,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2025095/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com