Retrieve only certain data

I would like to extract error message like 5601 - Pc Not Working. Please notify help desk. from the text file. How can I do that?
Ex.txt (166 Bytes)

Hi,

Can you try the following expression?

System.Text.RegularExpressions.Regex.Match(strData,"(?<=-+[\r\n]+).*?(?=[\r\n]+-+)").Value

img20200109-2

Regards,

Hi Yoichi, that worked.

But what if I want to extract the data like:
"------------------------------------
"5601 - Pc Not working. Please notify help desk.
"------------------------------------

Hi,

The following will work for both.

System.Text.RegularExpressions.Regex.Match(strData,"(?<=-+[\r\n]+""?)[^""]*?(?=[\r\n]+""?-+)").Value

Regards,

Hi @KahPou_Liew

use this expression

(?=5601).*

Thanks
Ashwin S

Hi,

It’s not work if the error is not fixed with the format.

For ex: Ex.txt (74 Bytes)

It returned nothing when I execute the process.

Hi,

Do you want to get the whole text after “Error:”? Can you try the following?

 System.Text.RegularExpressions.Regex.Match(strData,"(?<=Error:[\r\n]+)[\s\S]*").Value.Replace("""","").Replace("-","").Trim

Regards,

Yeah, it worked, one last question, how i can get the same content from the text file?
Ex.txt (99 Bytes)

Hi,

If you want get the string from “Error:” to “Resolution:”, the following will work.

System.Text.RegularExpressions.Regex.Match(strData,"(?<=Error:)[\s\S]*?(?=Resolution:)").Value.Replace("""","").Replace("-","").Trim

If you want get the string after “Resolution:”, try the following.

System.Text.RegularExpressions.Regex.Match(strData,"(?<=Resolution:)[\s\S]*").Value.Replace("""","").Replace("-","").Trim

Do these fit your intentions?

Regards,

Yes, but somehow if the resolution change to other word, it will not work. Is that a way to detect there is a blank new tab rather than putting as “resolution” so we can catch the error completely?

Hi,

How about the following?

System.Text.RegularExpressions.Regex.Match(strData,"(?<=Error:)[\s\S]*?(?=[\r\n]+.*?:)").Value.Replace("""","").Replace("-","").Trim

This processes line break + some word+“:”(Colon) as end phrase of the error record.

Regards,