谁能告诉我这个正则表达式有什么问题:
它旨在返回第一次出现的颜色,但一直返回最后一次出现。
$string = "Red is a sexy colour. Yellow too. Pink too. Blue too. Green too. Hehe.";
preg_match('/^.*\b(red|green|blue|yellow)\b.*$/i', $string, $colour );
echo $colour[1]; // Should say Red, but returns Green... o.O
$colour 上的 print_r 显示:
Array ( [0] => Red is a sexy colour. Yellow too. Pink too. Blue too. Green too. Hehe.
[1] => Green )