在多行

时间:2017-05-03 20:32:05

标签: regex

你好有这个字符串

  <20170503-18:19:09, FIXT.1.1:BANZAI->EXEC, event> (Initiated logon request)
  <20170503-18:19:09, FIX.4.4:BANZAI->EXEC, incoming> (8=FIX.4.4☺9=67☺35=A☺
  34=177☺49=EXEC☺52=20170503-18:19:09.298☺56=BANZAI☺98=0☺108=30☺10=092☺)
  <20170503-18:19:09, FIX.4.4:BANZAI->EXEC, event> 
  (Received logon) fdsfhffghgfhgjgf  177☺49=EXEC☺52=20170503-18:19:09.298☺
  56=BANZAI☺98 (Received logon) more stuff after this....

我想找到关键字“启动登录请求”之后是否有以下响应“收到登录”,当我写这样的正则表达式模式以适应多行和任何字符之间

 Initiated logon request.*[\S\s]*Received logon 

我把字符串中的最后一个关键字搞定了 结果

  Initiated logon request)
  <20170503-18:19:09, FIX.4.4:BANZAI->EXEC, incoming> (8=FIX.4.4☺9=67☺35=A☺
  34=177☺49=EXEC☺52=20170503-18:19:09.298☺56=BANZAI☺98=0☺108=30☺10=092☺)
  <20170503-18:19:09, FIX.4.4:BANZAI->EXEC, event> 
  (Received logon) fdsfhffghgfhgjgf  177☺49=EXEC☺52=20170503-18:19:09.298☺
  56=BANZAI☺98 (Received logon

我想要做的是在找到第一个关键字时停止正则表达式

  Initiated logon request)
  <20170503-18:19:09, FIX.4.4:BANZAI->EXEC, incoming> (8=FIX.4.4☺9=67☺35=A☺
  34=177☺49=EXEC☺52=20170503-18:19:09.298☺56=BANZAI☺98=0☺108=30☺10=092☺)
  <20170503-18:19:09, FIX.4.4:BANZAI->EXEC, event> 
  (Received logon

有没有办法做到这一点,谢谢你的帮助。

2 个答案:

答案 0 :(得分:4)

使用前瞻性肯定断言(?=...)和非贪婪量词*?

Initiated logon request[\S\s]*?(?=\(Received logon\))

https://regex101.com/r/TSfjiS/3

答案 1 :(得分:0)

要获得“收到登录”的第一场比赛,请使用:

Initiated logon request((?!Received logon)[\s\S])*Received logon

Regex 101

输出:

Initiated logon request)
<20170503-18:19:09, FIX.4.4:BANZAI->EXEC, incoming> (8=FIX.4.4☺9=67☺35=A☺
34=177☺49=EXEC☺52=20170503-18:19:09.298☺56=BANZAI☺98=0☺108=30☺10=092☺)
<20170503-18:19:09, FIX.4.4:BANZAI->EXEC, event> 
(Received logon