产品型号和代码的正则表达式代码

时间:2015-08-17 14:50:17

标签: regex vba

我找到了一个非常有用的正则表达式代码,以便提取产品代码here,这就是表达式:

\b((?:[a-z]+\S*\d+|\d\S*[a-z]+)[a-z\d_-]*)\b

它几乎完美无缺,但我只需要检测并提取长度至少为5位的产品代码。

For example, for the following strings:

5T COFFEE BREW FOR BLACK & DECKER DCM-601B
10T COFFEE BREW FOR BLACK & DECKER DCM-1100B
10T COFFEE BREW FOR BLACK & DECKER DCM-1100W
8T COFFEE BREW FOR BLACK & DECKER CM-1509
Rice Cookers 15T DOMESTIC USE RC5428, ELECTRIC BLACK & DECKER
Rice Cookers 15T RC/5723 DOMESTIC USE, ELECTRIC BLACK & DECKER
Rice Cookers B D REF.RC3203
Hand mixer, S / M, PS62509R
SLOW COOKING POTS, HAMILTON BEACH, HB33136T
OVEN 110V TOSTA SANKEY REF.TO-9
24 PZA METAL TEAPOT S / M CHINA REF: 92479
ELECTRIC RICE COOKER, 1.5 L ROYAL ROA-15SV
ELECTRIC RICE COOKER, 1.8 L ROYAL ROA-18SV
ELECTRIC RICE COOKER, 2.2 L ROYAL ROA-22SV
ELECTRIC RICE COOKER, 2.8 L ROYAL ROA-28SV
Waffle Makers DOMESTIC USE, ELECTRIC BLACK & DECKER G-49TD
2.00 PZA TOAST OVEN, METAL / GLASS ROYAL, CHINA, REF: RTH-28A
20.00 PZA RICE, METAL, BLACK & DECKER, CHINA, REF: RCB550S

I get:

5TDCM-601B
10TDCM-1100B
10TDCM-1100W
8TCM-1509
15TRC5428
15TRC/5723
REF.RC3203
PS62509R
HB33136T
REF.TO-9
92479
ROA-15SV
ROA-18SV
ROA-22SV
ROA-28SV
G-49TD
2.00RTH-28A
20.00RCB550S

Desired outcome:

DCM-601B
DCM-1100B
DCM-1100W
CM-1509
RC5428
RC/5723
REF.RC3203
PS62509R
HB33136T
REF.TO-9
92479
ROA-15SV
ROA-18SV
ROA-22SV
ROA-28SV
G-49TD
RTH-28A
RCB550S

我该怎么做?

2 个答案:

答案 0 :(得分:1)

如果我们假设您的代码包含5个或更多非空白符号,并且必须至少有1个数字,则代码的正则表达式为:

\b(?!\d+\.\d+)(?=\S*\d)\S{5,}\b

请参阅Demo 1

(?!\d+\.\d+)不允许使用1.234512.44等浮动/十进制数字。

答案 1 :(得分:1)

我不太确定我是否理解了您的问题,但您可以使用这样的正则表达式来获取您想要的产品代码:

((?:\w{2,}\.)?\w{1,}[.\/-]?\d+\w+)(?=\b)

<强> Working demo

enter image description here