Michael Aigner
Michael Aigner

Reputation: 5160

Regex: Substring start with a text

i have trouble to extract a error message. My error message start with error: and i want to have the text after the error: to the end of the line.

Can anybody help my please?

example: error: my error text

I wanna extract my error text

I'm only able to select the whole line.

Thanks in advance Tonka

Upvotes: 1

Views: 38

Answers (2)

Asunez
Asunez

Reputation: 2347

Since you did not specify what language you are using, you can use lookbehind.

DEMO

(?<=error: )(.*)

This looks for lines starting with "error:", and matches everything that follows afterwards. This will match a single line though.

Upvotes: 1

Aaron
Aaron

Reputation: 24812

If your messages always start with error: you might as well just use substring. You didn't say which language you were using, but this would do the trick in javascript :

message.substring(7)

Upvotes: 1

Related Questions