简体   繁体   English

正则表达式将短语与空格匹配

[英]RegEx to Match Phrase with Spaces

I have a line similar to the following: 我有一条类似于以下内容的行:

DESCRIPTION RIGHT HERE   EA  005   1            1      0000001     04/05/16              008

I am trying to extract the phrase DESCRIPTION RIGHT HERE . 我试图提取短语DESCRIPTION RIGHT HERE The description is different each time so I will not know the length of it from line to line. 每次的描述都不相同,所以我将不知道它的长度。 However, there is always more than one space after the description phrase. 但是,描述词组后面总是有多个空格。

What regex do I need to use in order to obtain the description phrase from the line? 为了从该行获取描述短语,我需要使用什么正则表达式?

You could do it like this I guess. 我猜你可以这样做。
Description to Description or end of string. 对描述的描述或字符串的结尾。
Answer in capture group 1. 在捕获组1中回答。

DESCRIPTION RIGHT HERE\\s(.*?)(?=DESCRIPTION RIGHT HERE|$)

^([^$]*?)\\s\\s应该将所有内容都懒惰地匹配,后跟两个空格,这意味着您将只获得第1组中的描述。

Please try: 请试试:

^(.*?)(?=\s{2})

LIVE DEMO 现场演示

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM