我有这个正则表达式:
([http://some.url.com/index.php?showtopic=\"]*)([0-9]+(?:\.[0-9]*)?)
用于从论坛中提取主题链接
现在当我在我的脚本中使用它时
$url = "([http://some.url.com/index.php?showtopic=\"]*)([0-9]+(?:\.[0-9]*)?)";
preg_match_all 吐出:“未知修饰符‘(’”
这也是对preg_match的调用
preg_match_all($url, $str, $matches,PREG_OFFSET_CAPTURE,3);
谁能帮我解决这个明显愚蠢的问题
最佳答案
您需要将正则表达式用定界符包裹起来。任何不是特殊 PCRE 元字符的字符都可以,所以我将使用 #
:
$url = "#([http://some.url.com/index.php?showtopic=\"]*)([0-9]+(?:\.[0-9]*)?)#";
您可以在 the PHP manual section for PCRE delimiters 中了解有关分隔符的更多信息.
关于PHP RegEx 错误未知修饰符 '(',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2888496/