PHP:Warning:preg_match()[function.preg match]:未知修饰符'';在里面

PHP:Warning:preg_match()[function.preg match]:未知修饰符'';在里面,php,regex,preg-match,Php,Regex,Preg Match,我知道也有类似的问题,我已经研究了其中的一些问题,但是即使有了这些知识,我仍然无法解决我自己的问题。如果有人能向我指出这个问题,我将不胜感激 function getCategories($source) { $pattern = "<span class=\".*\" id=\".*\">.*<.span>.*<table class=\".*\".*> <tr> <th.* <.th> <th.* <.th

我知道也有类似的问题,我已经研究了其中的一些问题,但是即使有了这些知识,我仍然无法解决我自己的问题。如果有人能向我指出这个问题,我将不胜感激

function getCategories($source)
{
    $pattern = "<span class=\".*\" id=\".*\">.*<.span>.*<table class=\".*\".*>
<tr>
<th.*
<.th>
<th.*
<.th>
<th.*
<.th>
<th.*
<.th>
<th.*
<.th>
<th.*
<.th><.tr>
(<tr id=\".*\">\n(.*\n){6}<.td><.tr>(<.table>)?\n)*";

    preg_match($pattern, $source, $categories);

    return $categories;
}
第31行是“预匹配(…)”

我确信正则表达式应该可以工作,因为我已经在一个工具中对它进行了测试,并且正确的字符串肯定正在被传递,它只是不喜欢我的正则表达式。表达出于某种原因。我试着确保所有的东西要么逃走了,要么换成了新的。(在逃离时的最后手段/不起作用)

任何帮助都将不胜感激!谢谢大家!


~Andrew

您应该使用分隔符字符开始和结束模式字符串;通常这是
/
,但由于您正在匹配HTML,请选择明天不会使用的内容。

您缺少模式两端的分隔符,因此它看到了这一点

$pattern = "<span class=\".*\" id=\".*\">.*<.span>.*<table class=\".*\".*>
            ^ opening delimiter            ^ closing delimiter followed by a modifier

这似乎已经摆脱了警告,谢谢!
$pattern = "<span class=\".*\" id=\".*\">.*<.span>.*<table class=\".*\".*>
            ^ opening delimiter            ^ closing delimiter followed by a modifier
$pattern = "/<span class=\".*\" id=\".*\">.*<.span>.*<table class=\".*\".*>
<tr>
<th.*
<.th>
<th.*
<.th>
<th.*
<.th>
<th.*
<.th>
<th.*
<.th>
<th.*
<.th><.tr>
(<tr id=\".*\">\n(.*\n){6}<.td><.tr>(<.table>)?\n)*/";