I need a help with regex for MPN patterns, mostly for this one:
Bosch HBA13B250B Built-in Electric Single Oven
so 3 letters followed by at least 1 digit and then until word boundry is reac开发者_开发技巧hed should extract
HBA13B250B
Do you have any ideas how to put it into regex pattern?
Use this:
preg_match('#\b([A-Z]{3}[0-9].*?)\b#', $text, $match);
or, to better restrict possible values:
preg_match('#\b([A-Z]{3}[0-9][0-9A-Z]*)\b#', $text, $match);
$text = "Bosch HBA13B250B Built-in Electric Single Oven";
$pattern = '/\b([A-Z]{3}[0-9]+.*)\b/i';
echo "Matches: " . preg_match($pattern, $text);
精彩评论