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


Unknown modifier 'g' PHP regex error

我的图案是:/(productimages'/)('w*)('/v'/)('w*)(.jpg)/g和数据:http://gskinner.com/RegExr/?2ujor

和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];
}}

result: Warning: preg_match() [function.]preg-match]:未知修饰语"g"

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

result: Warning: preg_match_all() [function。preg-match-all]:未知修饰符"g"

这个解决方案不工作!:|未知修饰词'g'在…"在PHP中使用preg_match时?

我该怎么办?

切换到preg_match_all是正确的,现在您需要做的就是从正则表达式中删除'g':

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

没有g修饰语

删掉g就行了

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