首页 > 解决方案 > Regex: user pattern this or another

问题描述

I have strings like:

Name 31X10.50R15 109S RX706 SUV

Brand 131/70R11 NU8 Word RX808

Word 6.00R16 983/222 10PR MONO S+V

I need to match 31X10.50 and 6.00R16 only from strings, as you can see there is no pattern like "digit X digit" or "digit R digit" in the second string line.

My preg_match was this:

/(\d*\.?\d+?)x\K\d*\.?\d+?|\d*\.?\d+?r\d*/i

With this line: (\d*\.?\d+?)x\K\d*\.?\d+? I am finding 31 and 10.5 from first string.

With next line: \d*\.?\d+?r\d* I hope to find 6.00R16 and took only 6.00

So my regex logic is to match 31X10.50 or 6.00R16 from strings. But second line is not working for me...

what I am doing wrong?

标签: regex

解决方案


正则表达式

该代码适用于包含的任何字符串.

(\d+\.\d+)\w+

推荐阅读