mardi 13 juin 2017

How to use a single regex to extract a substring from this string?

I have these strings:

Case 1: System returned to ROM by unknown reload cause - reason ptr 0xBFC2B644, PC 0x60452AC0, address 0x0 at 16:03:27 MSD Thu Jun 8 2006

output should be: unknown reload cause - reason ptr 0xBFC2B644, PC 0x60452AC0, address 0x0 (string between "by" and "at")

Case 2: System returned to ROM by watchdog timer expired

output should be: watchdog timer expired (String after "by" till the end since "at" is not present)

How can i use a regex to extract the substring between "by" and "at"(if "at" is not present then string from by till the end)

This regex i came up with matches the substring only if the string has the at part.

(?<=by)(.)?(at)+(?!at\s+\d\d:\d\d:\d\d\s.?\d\s+\d\d\d\d)

String i used to check: a SegV exception, PC 0x325D558 at 20:34:38 UTC Fri Jun

output for the above regex: error - a SegV exception, PC 0x325D558

Aucun commentaire:

Enregistrer un commentaire