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

标签 php regex

我的模式是:/(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/

相关文章:

php - 在 Wordpress 的循环中显示每个帖子的类别名称

php - 使用for循环从数组中获取最大数字

php - 使用多行字符串的正则表达式修剪行并缩小空格

regex - 在 MySQL (InnoDB) 中查找最佳匹配行

php - 如何在 Smarty 中使用一组 PHP 函数

php - 将值从 View 文件发送到 yii 中的小部件

PHP循环遍历一半数组

Java长正则表达式

java - 如何在字符串中只保留不同类型的字母,例如 : latin alphabet, 片假名、西里尔字母

Javascript 正则表达式 "replace(/[ -_]/g)"删除数字?