正则表达式 - 如何选择从模式到列表末尾的所有行

时间:2015-03-27 20:10:10

标签: regex list match

是否有可能选择最后一条" Jhon Gerome"匹配(底部的一个)到列表的末尾?是一个剪贴板文本,我使用.Net Regex。

[2/3/2015 4:51:27 PM] *** Call to Bob Robinson ***
[2/3/2015 4:52:51 PM] Bob Robinson: check this out
[2/3/2015 4:55:34 PM] *** Call ended, duration 04:06 ***
[2/9/2015 7:52:58 PM] Jhon Gerome: you take to long
[2/25/2015 4:05:25 PM] Jhon Gerome: I am reading
[2/25/2015 4:05:26 PM] Jhon Gerome: ok
[3/10/2015 11:17:27 PM] Bob Robinson: how are you?
[3/10/2015 11:17:35 PM] Jhon Gerome: fine thanks
[3/10/2015 11:17:41 PM] Bob Robinson: are you there?
[3/10/2015 11:17:41 PM] Bob Robinson: can you hear me?
[2/25/2015 4:23:23 PM] *** Call from Bob Robinson ***
[2/25/2015 5:36:38 PM] *** Call ended, duration 1:13:15 ***
[3/10/2015 11:16:46 PM] *** Call to Bob Robinson, no answer.
Send video message ***
[3/10/2015 11:18:11 PM] Bob Robinson: whats up man
[3/10/2015 11:20:32 PM] Bob Robinson: Jhon?
[3/10/2015 11:20:32 PM] Bob Robinson: are you there?

请注意所有这些行以CRLF结尾。现在我首先需要做的就是......

fine thanks
[3/10/2015 11:17:41 PM] Bob Robinson: are you there?
[3/10/2015 11:17:41 PM] Bob Robinson: can you hear me?
[2/25/2015 4:23:23 PM] *** Call from Bob Robinson ***
[2/25/2015 5:36:38 PM] *** Call ended, duration 1:13:15 ***
[3/10/2015 11:16:46 PM] *** Call to Bob Robinson, no answer.
Send video message ***
[3/10/2015 11:18:11 PM] Bob Robinson: whats up man
[3/10/2015 11:20:32 PM] Bob Robinson: Jhon?
[3/10/2015 11:20:32 PM] Bob Robinson: are you there?

到目前为止使用此代码实现了:(?s)。* Jhon Gerome(\ 1)感谢" Fede"

但是后来我会发现>>> Bob Robinson之后的所有内容:<<<所以我想以这样的方式结束,它只是在一条线上并不重要。

are you there?
can you hear me?
whats up man
Jhon?
are you there?

是否有可能通过一个正则表达式代码实现这一目标?或最多两个?任何指针?感谢。

1 个答案:

答案 0 :(得分:1)

你可以使用s标志这样的正则表达式:

.*Jhon Gerome(.*)

<强> Working demo

MATCH 1
1.  [385-852]   `: fine thanks
[3/10/2015 11:17:41 PM] Bob Robinson: are you there?
[3/10/2015 11:17:41 PM] Bob Robinson: can you hear me?
[2/25/2015 4:23:23 PM] *** Call from Bob Robinson ***
[2/25/2015 5:36:38 PM] *** Call ended, duration 1:13:15 ***
[3/10/2015 11:16:46 PM] *** Call to Bob Robinson, no answer.
Send video message ***
[3/10/2015 11:18:11 PM] Bob Robinson: whats up man
[3/10/2015 11:20:32 PM] Bob Robinson: Jhon?
[3/10/2015 11:20:32 PM] Bob Robinson: are you there?`

或者你也可以使用内联标志:

(?s).*Jhon Gerome(.*)

然后你必须抓住捕获组的内容。

相关问题