regex - 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?
解决方案
正则表达式
该代码适用于包含的任何字符串。.
(\d+\.\d+)\w+
推荐阅读
- python-3.x - 在双轴中绘制价格线和成交量点
- r - 从位于 R 中不同文件夹中的 Excel 文件导入工作表
- apache-spark - 如何强制 Spark Dataframe 在所有工作节点之间拆分?
- maven - 设置 project.build.sourceDirectory 是否适用于 Maven 属性?
- javascript - 光标位置在 Firefox 中使用 div contenteditable 结束
- c# - 有没有一种干净的方法可以从 appsettings.json 获取属性,并在类属性中使用它们?
- ssl - 使用 Pyspark 通过 SSL 连接到 DB2
- javascript - 如何使用捕获错误处理角度错误
- html - 三列CSS滚动表布局错误
- reactjs - 我应该使用 TypeScript 输入什么类型的 react-bootstrap 事件?