这些是输入字符串:
第 1 行:item1 199-30, 1/1/2021
第 2 行:item2 29 minus 5, 1/1/2021
我想使用正则表达式来提取这样的:
Line 1: 199, 30
Line 2: 29,5
我试过了,这是我的正则表达式:
([\d]+)[-|(\s*minus\s*)]([\d]+)
仅匹配第 1 行。
使用您显示的示例,请尝试以下正则表达式。
^item\d+\s+(\d+)(?:-|\s+minus)\s*(\d+)
Run Code Online (Sandbox Code Playgroud)
说明:为以上添加详细说明。
^item\d+\s+ ##Matching item from starting of value followed by 1 or more digits followed by 1 or more space occurrences.
(\d+) ##Creating 1st capturing group which has digits in it.
(?:-|\s+minus)\s* ##In a non-capturing group matching either - OR 1 or spaces followed by minus. Matching 0 or more spaces.
(\d+) ##Creating 2nd capturing group which has digits in it.
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
88 次 |
| 最近记录: |