【问题标题】:Regex Find the value after a keyword and remove everything else including the keyword正则表达式查找关键字后的值并删除包括关键字在内的所有其他内容
【发布时间】:2023-02-20 20:52:13
【问题描述】:

我正在尝试读取值

Colli 182515612/OT 37/SA

我需要的唯一值是182515612。由于在文件中找到多个 9 位数字,我需要正则表达式来查找 Colli,然后将后面的 9 位值与其他所有值分开。

我试过 [^colli ](\d{9})[colli ][0-9]{9} 第二个似乎至少读出了值,但它似乎只是在寻找前面有空格的数字,所以它也可能读出其他值。

【问题讨论】:

    标签: regex


    【解决方案1】:

    这个正则表达式:

    ^Colli+s+Kd{9}
    

    online demo

    正则表达式匹配如下:

    Node Explanation
    ^ the beginning of the string
    Colli Colli
    s+ whitespace ( , , , , and " ") (1 or more times (matching the most amount possible))
    K resets the start of the match (what is Kept) as a shorter alternative to using a look-behind assertion: look arounds and Support of K in regex
    the boundary between a word char (w) and something that is not a word char
    d{9} digits (0-9) (9 times)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-01-24
      • 2011-05-02
      • 2018-08-10
      • 1970-01-01
      • 2017-08-29
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多