regex - Notepad++ 正则表达式: Search for long strings which could contain newlines

标签 regex notepad++ newline multiline

给定一个包含 100000 多条日志消息的文件,例如:

2017-08-10T14:49:09: Debug: D-UNK-000-000: [Event Processor] connectorStatus:   Pending
2017-08-10T14:49:09: Debug: D-UNK-000-000: [Event Processor] context:   <DataItem type="System.Availability.StateData" time="2017-08-04T01:10:59.9525690+02:00"><ManagementGroupId>{05120214-5C27-A4EE-D32B-09CB2239421C}</ManagementGroupId><Property Name="Details" VariantType="8">There are 1 messages attached



03.08.2017 21:00:12

Title: Mail sync issue



User Impact: Users are unable to sync emails using Apple Mail on their Mac computers.

</Property></DataItem>
2017-08-10T14:49:09: Debug: D-UNK-000-000: [Event Processor] context_ManagementGroupId: {05120214-5C27-A4EE-D32B-09CB2239421C}
2017-08-10T14:49:09: Debug: D-UNK-000-000: [Event Processor] context:   null
2017-08-10T14:49:09: Debug: D-UNK-000-000: [Event Processor] context_HealthServiceId:   390382B5-C177-0529-DDC0-F2969F667E49

每条日志消息都在一个以时间戳开头的新行开始。但是一些日志消息跨越多行;在上面的示例中,看到包含“上下文:”的第二行,然后是一些嵌入了多个换行符的任意 xml。因此,在上面的示例中,正好有 5 条日志消息。

我正在寻找很长的日志消息,比如超过 15000 个字符。

我可以使用 Notepad++ 搜索此模式(选择选项“。匹配换行符”)逐步浏览所有相关日志消息:

context:(.+?)2017-0\d-\d\dT\d\d:\d\d:\d\d:

但我没有扩展它只会给我长的。

我希望下面的代码可以工作,但运气不好(它选择了整个文件):

context:(.+?){15000,}2017-0\d-\d\dT\d\d:\d\d:\d\d:


如果用 Notepad++ 做不到,我也愿意使用其他工具,包括 linux box 上的命令行。


没有必要,但如果容易的话:
搜索我已经解释过的相同内容,并用它的长度(字符数)替换整个 xml 字符串。

最佳答案

你可以使用

(?s)context:(?:(?!2017-0\d-\d\dT\d\d:\d\d:\d\d:).){350,}

解释:

  • (?s) - DOTALL 模式开启(与 相同。 匹配启用的换行符)
  • context: - 文字子串
  • (?:(?!2017-0\d-\d\dT\d\d:\d\d:\d\d:).){350,} - 350不开始 2017-0\d-\d\dT 序列的任何字符 (.) 或多次出现 ({350,})\d\d:\d\d:\d\d: 子模式。

(?:(?!).)* 是所谓的 greedy tempered token .

根据需要调整限制量词的最小阈值。

enter image description here

关于regex - Notepad++ 正则表达式: Search for long strings which could contain newlines,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45631096/

相关文章:

c# - 正则表达式在线匹配,但在 C# 代码中不匹配

javascript - 替换所有图像的图像源

regex - 对 Perl 中正则表达式基本规则的困惑

text - 如何删除之前的文字|记事本中的字符++

python - 为什么用回车\r打印不抑制换行符?

vba userforms回车行为

regex - Perl 正则表达式从匹配中排除可选单词

asp.net - 需要正则表达式来验证 dd-MMM-yyyy 格式的日期

regex - 添加到包含特定单词并以 x 开头的行尾

regex - NotePad++ 更换问题