Regex_extract字符串后的下一行(仅第一行) [英] Regex_extract the next (and only the first) line after string
本文介绍了Regex_extract字符串后的下一行(仅第一行)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
使用正则表达式(在Ruby上),如何像这样在字符串之后提取一行(仅下一行)
Using regex (on Ruby), how can I extract one line (only next line) after strings, like this
标题:
这是我要提取的文字
不是这个
都不是
Title:
this is the text I'd like to extract
Not this one
Neither this
我设法使用"Lookahead and Lookbehind"提取文本,如下所示:
I managed to extract the text using "Lookahead and Lookbehind" like this:
puts text.scan(/Title:[^;]*)Not this one/)
但并非总是提到第二部分(不是这个")
but the second part ("Not this one") is not always mentionned
推荐答案
^(?<=Title:\n)([^\n]+$)
请检查.
这篇关于Regex_extract字符串后的下一行(仅第一行)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文