Notepad++ 正则表达式:搜索可能包含换行符的长字符串
Notepad++ regular expression: Search for long strings which could contain newlines
给定一个包含 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
每条日志消息都在一个以时间戳开头的新行开始。但是一些日志消息跨越多行;在上面的示例中,看到包含“context:”的第二行,然后是一些任意的 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 框上的命令行。
没有必要,但如果容易的话:
搜索我已经解释过的内容,并用它的长度(字符数)替换整个 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,}
- 不开始 2017-0\d-\d\dT\d\d:\d\d:\d\d:
子模式序列的任何字符 (.
) 出现 350 次或更多次 ({350,}
)。
(?:(?!).)*
就是所谓的。
根据需要调整限制量词的最小阈值。
给定一个包含 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
每条日志消息都在一个以时间戳开头的新行开始。但是一些日志消息跨越多行;在上面的示例中,看到包含“context:”的第二行,然后是一些任意的 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 框上的命令行。
没有必要,但如果容易的话:
搜索我已经解释过的内容,并用它的长度(字符数)替换整个 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,}
- 不开始2017-0\d-\d\dT\d\d:\d\d:\d\d:
子模式序列的任何字符 (.
) 出现 350 次或更多次 ({350,}
)。
(?:(?!).)*
就是所谓的
根据需要调整限制量词的最小阈值。