我的模式是:/(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]: Unknown modifier '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]: Unknown modifier 'g'
此解决方案无效! :| "Unknown modifier 'g' in..." when using preg_match in PHP?
我该怎么办?
最佳答案
切换到 preg_match_all
是正确的,现在您需要做的就是从正则表达式中删除“g”:
$regexp = '/(productimages\/)(\w*)(\/v\/)(\w*)(.jpg)/';
关于php - 未知修饰符 'g' PHP 正则表达式错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7292582/