【问题标题】:Regex_extract the next (and only the first) line after stringRegex_extract 字符串后的下一行(也是第一行)
【发布时间】:2015-12-08 21:42:26
【问题描述】:

使用正则表达式(在 Ruby 上),如何在字符串之后提取一行(仅下一行),像这样

标题:
这是我要提取的文本
不是这个
这个也没有

我设法使用“Lookahead and Lookbehind”来提取文本,如下所示:

puts text.scan(/Title:[^;]*)Not this one/)

但并不总是提到第二部分(“不是这个”)

【问题讨论】:

    标签: ruby regex parsing


    【解决方案1】:
    ^(?<=Title:\n)([^\n]+$)
    

    DEMO

    请检查一下。

    【讨论】:

    • 最后一部分的 () 是可选的,你可能不需要。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-11-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多