preg_match_all: Warning: preg_match_all(): Unknown modifier '(' in [duplicate]

我只是一个虾纸丫 提交于 2019-12-25 02:25:23

问题


Possible Duplicate:
preg_match() Unknown modifier '[' help

I am trying to match this pattern

 $regex_pattern = '<td id="(\w+)" class="(\w+)">(\w+).com<\/td>';
 preg_match_all($regex_pattern, $result, $matches);
 print_r($matches);

But I am getting this error: Warning: preg_match_all(): Unknown modifier '(' in

What's wrong in my regex pattern?


回答1:


Add delimiters to your pattern

When using the PCRE functions, it is required that the pattern is enclosed by delimiters. A delimiter can be any non-alphanumeric, non-backslash, non-whitespace character.

Often used delimiters are forward slashes (/), hash signs (#) and tildes (~).

 $regex_pattern = '/<td id="(\w+)" class="(\w+)">(\w+).com<\/td>/';
 preg_match_all($regex_pattern, $result, $matches);
 print_r($matches);


来源:https://stackoverflow.com/questions/11232375/preg-match-all-warning-preg-match-all-unknown-modifier-in

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!