开发者

MPN extraction regex

开发者 https://www.devze.com 2023-03-30 07:43 出处:网络
I need a help with regex for MPN patterns, mostly for this one: Bosch HBA13B250B Built-in Electric Single Oven

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);
0

精彩评论

暂无评论...
验证码 换一张
取 消