RegEx:删除第一个单词后的所有内容到下一行 [英] RegEx: Delete everything after the first word to the next line

查看:27
本文介绍了RegEx:删除第一个单词后的所有内容到下一行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

用什么正则表达式删除每行除第一个单词以外的所有内容:

What regular expression is used to delete everything except the first word from each line:

数据:

JAMES          3.318  3.318      1
JOHN           3.271  6.589      2
ROBERT         3.143  9.732      3

我正在尝试在 Notepad++ 中执行此操作作为替代.

I'm trying to do this in Notepad++ as a replace.

推荐答案

取决于您使用的正则表达式实现.

Depends on what regex implementation you're using.

正则表达式 ^[A-Za-z_]+ 将捕获一行中的第一个单词.因此,如果您的实施允许,您可以捕获第一个单词并将其打印出来,然后就可以开始了.

the regex ^[A-Za-z_]+ will capture the first word on a line. So, you can capture this first word and print it out and you're good to go, if your implementation permits.

如果需要使用替代,可以用^([A-Za-z_]+).*代替\1例如,在 vi 中,您将使用命令 :%s/^\([A-Za-z_]+\).*/\1/

If you need to use substitute, you can substitute ^([A-Za-z_]+).* for \1 E.g., in vi, you would use the command :%s/^\([A-Za-z_]+\).*/\1/

这篇关于RegEx:删除第一个单词后的所有内容到下一行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆