PHP中的正则表达式问题

时间:2010-12-12 19:32:18

标签: php regex

我需要让这个工作:

PHP

第一场比赛应该寻找以下内容:

                  $pattern1 = "/<div rawurl\=\"(.*)\" class/"; // Add wildcard here as there will be 10 matches, we are only looking for one.
                  preg_match($pattern1, $file, $out1);

然后运行第二次检查以查看我们定义的变量是否存在于第一个preg_match $out1的结果中,

                  $pattern2 = preg_quote("http://domain.com/extras/?possiblequery" ."/");
                  $pattern2 = "/".$pattern2."/";
                  if (preg_match($pattern2, $file, $out)); 
                    { return result

我在编写这两条preg_match行的正则表达式时遇到了麻烦...我很确定它是带有通配符的第一个...欢迎任何帮助!

2 个答案:

答案 0 :(得分:1)

您需要使用preg_quote的第二个参数指定分隔符:

preg_quote("http://example.com/extras/?possiblequery", "/")

答案 1 :(得分:0)

据我了解,'。*'之后缺少'?'似乎对我有用。

你怎么称呼widcard?