Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/293.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
未知修饰符';g';PHP正则表达式错误_Php_Regex - Fatal编程技术网

未知修饰符';g';PHP正则表达式错误

未知修饰符';g';PHP正则表达式错误,php,regex,Php,Regex,我的模式是:/(productimages\/)(\w*)(\/v\/)(\w*)(.jpg)/g 和数据: 和php代码: $regexp = ' /(productimages\/)(\w*)(\/v\/)(\w*)(.jpg)/g'; if(preg_match("$regexp", $input, $matches, PREG_SET_ORDER)) { for($i=0;$i<14;$i++){ echo '--->'.$i.'-->'.$matches[0][$i

我的模式是:
/(productimages\/)(\w*)(\/v\/)(\w*)(.jpg)/g
和数据:

和php代码:

$regexp = ' /(productimages\/)(\w*)(\/v\/)(\w*)(.jpg)/g';
if(preg_match("$regexp", $input, $matches, PREG_SET_ORDER)) { 
for($i=0;$i<14;$i++){
echo '--->'.$i.'-->'.$matches[0][$i];

}}
$regexp='/(productimages\/)(\w*)(\/v\/)(\w*)(.jpg)/g';
如果(preg_match($regexp“,$input,$matches,preg_SET_ORDER)){

对于($i=0;$i切换到
preg\u match\u all
是正确的,现在只需从正则表达式中删除“g”:

$regexp = '/(productimages\/)(\w*)(\/v\/)(\w*)(.jpg)/';

删除那个g,它就会工作

$regexp = '/(productimages\/)(\w*)(\/v\/)(\w*)(.jpg)/';

没有G,它只返回第一个匹配的字符串!
-->0-->productimages/Routers/v/CISCO1941.jpg-->1-->productimages/-->2-->Routers-->3-->/v/-->4-->CISCO1941-->5-->.jpg-->6-->7-->8-->9-->10-->11-->12-->13-->我想要所有匹配的字符串!删除G只返回第一个匹配的字符串$matches[0][0]与您的问题无关,但您应该使用
\.
匹配点。
$regexp = '/(productimages\/)(\w*)(\/v\/)(\w*)(.jpg)/';