如何打印一行的一部分第 2 部分
使用 Groovy,我希望抓取制表符分隔行的两个部分。以示例行为例:
onefishtwofishredfishbluefish
----(每个字符制表符/t
分隔)
假设我想打印one
code> 然后我想打印 redfishblue
我该怎么做?
或者,假设我想打印 one
,然后打印 red
后面的字符(单词)数量?或者介于两个和蓝色
之间?
上一个问题产生了这个响应,用于打印行的某个部分之后的所有内容:
c = ~/.*red(.*)/
m = line =~ c
if (m) {
println m[0][1]
}
产生 fish bluefish
但我对正则表达式的能力不够,无法适当地修改它。我尝试了几次迭代,在其中插入 /t
并修改我的捕获表达式,但我还没有弄清楚。这是三四个问题合而为一,我们将不胜感激。谢谢!!
Using Groovy, I wish to grab two parts of a tab-separated line. Take the example line:
one fish two fish red fish blue fish
----(each character tab /t
separated)
Suppose I want to print one
and then I want to print red fish blue
How can I do this?
Alternatively, suppose I want to print one
and then a count of the number of characters (words) following red
? Or between two and blue
?
A previous question yielded this response for printing everything following a certain part of the line:
c = ~/.*red(.*)/
m = line =~ c
if (m) {
println m[0][1]
}
to yield fish blue fish
but I'm not comptetent enough with regex's to modify this appropriately. I've tried a few iterations, inserting /t
in there and modifying my capturing expression but I've not figured it out. This is three or four questions in one, any help is appreciated. Thanks!!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)