Greedy and non-greedy matching
<?
$meats = "<b>Chicken</b>, <b>Beef</b>, <b>Duck</b>";
preg_match_all('@<b>.*?</b>@',$meats,$matches);
foreach ($matches[0] as $meat) {
print "Meat A: $meat\n";
}
preg_match_all('@<b>.*</b>@',$meats,$matches);
foreach ($matches[0] as $meat) {
print "Meat B: $meat\n";
}
?>
Related examples in the same category