简体   繁体   English

正则表达式结果输出单个匹配项,多个匹配项

[英]Regex result outputs single match for multiple matches

I'm having a file with multiple newlines at "Error message" field. 我在“错误消息”字段中具有多个换行符的文件。 I need to replace the newlines into space, so it can be loaded as single row. 我需要将换行符替换为空格,因此可以将其作为单行加载。

But I'm unable to capture multiple matches. 但是我无法捕获多个匹配项。 My regex outputs single match for the whole file. 我的正则表达式输出整个文件的单个匹配项。 I need help to create regex which will give me 3 matches for the example provided. 我需要帮助来创建正则表达式,这将为我提供3个匹配的示例。

https://regex101.com/r/DoED69/1 https://regex101.com/r/DoED69/1

Regex used 正则表达式使用

^breakmantis.*;(Error;[\s\S]*;Regular;)[\s\S]*breakmantis

**Current File with Newlines : ** **带换行符的当前文件:**

name;brand;environment;center;Error
breakmantis;Kordel;Production;Bleep Eyeglow;Error;"The message did not pass the validation: 
Error Message='PriceTag' is mandatory, under field Price.
Error Message='PriceAmount' is mandatory, under field Price.
Error Message='BaseQuantity' is mandatory, under field Price.";Regular;;;;24 Apr 2019 14:34 CEST
breakmantis;Kordel;Production;Bleep Eyeglow;Error;"The message did not pass the validation: 
Error Message='PriceTag' is mandatory, under field Price.
Error Message='PriceAmount' is mandatory, under field Price.
Error Message='BaseQuantity' is mandatory, under field Price.";Regular;;;;24 Apr 2019 14:35 CEST
breakmantis;Kordel;Production;Bleep Eyeglow;Error;"The message did not pass the validation: 
Error Message='PriceTag' is mandatory, under field Price.
Error Message='PriceAmount' is mandatory, under field Price.
Error Message='BaseQuantity' is mandatory, under field Price.";Regular;;;;24 Apr 2019 14:36 CEST

Expected Result : 预期结果 :

breakmantis;Kordel;Production;Bleep Eyeglow;Error;"The message did not pass the validation: Error Message='PriceTag' is mandatory, under field Price.Error Message='PriceAmount' is mandatory, under field Price.Error Message='BaseQuantity' is mandatory, under field Price.";Regular;;;;24 Apr 2019 14:34 CEST
breakmantis;Kordel;Production;Bleep Eyeglow;Error;"The message did not pass the validation: Error Message='PriceTag' is mandatory, under field Price.Error Message='PriceAmount' is mandatory, under field Price.Error Message='BaseQuantity' is mandatory, under field Price.";Regular;;;;24 Apr 2019 14:35 CEST
breakmantis;Kordel;Production;Bleep Eyeglow;Error;"The message did not pass the validation: Error Message='PriceTag' is mandatory, under field Price.Error Message='PriceAmount' is mandatory, under field Price.Error Message='BaseQuantity' is mandatory, under field Price.";Regular;;;;24 Apr 2019 14:36 CEST

Try matching: 尝试匹配:

\\n(Error Message=) \\ n(错误消息=)

and substitute with 并用

\\1 \\ 1

Add leading spaces in the substitution to suit your needs. 在替换中添加前导空格以适合您的需求。

How about that? 那个怎么样?

^breakmantis.*;(Error;[\\s\\S]*?)CEST$

Regex: https://regex101.com/r/DoED69/2 正则表达式: https : //regex101.com/r/DoED69/2

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

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