2011-09-03 36 views
3

我的模式是:/(productimages\/)(\w*)(\/v\/)(\w*)(.jpg)/g 和数据:http://gskinner.com/RegExr/?2ujor未知的修饰的 'g' PHP正则表达式错误

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

}} 

结果:警告:的preg_match()[function.preg-匹配]:未知的修饰 '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]; 

}} 

结果:警告:preg_match_all()[function.preg-全匹配]:未知 修改 'G'

这个解决方案没有奏效! :| "Unknown modifier 'g' in..." when using preg_match in PHP?

我该怎么办?

+0

完全无关的问题,但你应该使用'\ .'匹配点。 –

回答

5

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

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

我想要所有匹配的字符串!删除g只返回第一个匹配的字符串$ matches [0] [0] – Amino

2

There's no g modifier

删除G和它会工作

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

without 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 - > – Amino

+0

@Amino:使用preg_match_all() – genesis

相关问题