Regex 如何在groovy中获得正则表达式匹配后的行?
我应该得到与行“abcd efgh”匹配的字符串后面的行。 有人能帮我写一个groovy正则表达式吗 对于文本中的eg:Regex 如何在groovy中获得正则表达式匹配后的行?,regex,groovy,Regex,Groovy,我应该得到与行“abcd efgh”匹配的字符串后面的行。 有人能帮我写一个groovy正则表达式吗 对于文本中的eg: dafdsdf abcd efgh hello hi new 结果应该是: hello hi new 请帮忙?您不需要正则表达式 def text = '''dafdsdf abcd efgh hello hi new''' text.split('\n') // Split into lines .dropWhile
dafdsdf
abcd efgh
hello
hi
new
结果应该是:
hello
hi
new
请帮忙?您不需要正则表达式
def text = '''dafdsdf
abcd efgh
hello
hi
new'''
text.split('\n') // Split into lines
.dropWhile { it != 'abcd efgh' } // Drop all lines before the text
.drop(1) // Drop the line with the text
.each { println it } // Print the rest out
您不需要正则表达式
def text = '''dafdsdf
abcd efgh
hello
hi
new'''
text.split('\n') // Split into lines
.dropWhile { it != 'abcd efgh' } // Drop all lines before the text
.drop(1) // Drop the line with the text
.each { println it } // Print the rest out
这个dropwhile函数是否与正则表达式匹配@tim_yatesIt可以,它只需要一个布尔值
.dropWhile{!(it=~/abcd.+/)}
将一直下降,直到行出现abcd
,然后是任何其他字符。它起作用了。我们是否可以在其中包含一个条件以打印到某个限制@tim_yatesI我不明白,你能解释一下吗?我们能限制每一行的内部打印只打印到某一行吗。在上面的例子中,假设它只打印到“hi”@tim_Yates此dropwhile函数是否与正则表达式匹配@tim_yatesIt可以,它只需要一个布尔值.dropWhile{!(it=~/abcd.+/)}
将一直下降,直到行出现abcd
,然后是任何其他字符。它起作用了。我们是否可以在其中包含一个条件以打印到某个限制@tim_yatesI我不明白,你能解释一下吗?我们能限制每一行的内部打印只打印到某一行吗。在上面的例子中,假设它只打印到“hi”@蒂姆·耶茨