sbstnmrwld
sbstnmrwld

Reputation: 36

Regex find strings between colon

I try to regex the following string

 : hostname: Oct 16 03:49:39.515: %BLA: message

and want to get the strings between the ": " and the last string after the last ": "

when I use : (.+?): I get hostname.

Unfortenately I am not able to get Oct 16 03:49:39.515, %BLA and message. I need single regex for every substring, I don't want to have them all in one.

Upvotes: 0

Views: 2439

Answers (1)

anubhava
anubhava

Reputation: 785731

Since graylog2 is written in Java I believe lookarounds should work. Try this regex:

(?<=: )(.+?)(?=: |$)

RegEx Demo


Update: If you really need 4 different regex for 4 components then use:

RegEx 1:

(?<=: )(.+)(?=(?:: .+){3}[^:]*$)

RegEx 2:

: [^:]*: (.+?)(?=: )

RegEx 3:

: [^:]*: .+?: ([^:]+)

RegEx 4:

(?<=: )([^:]+)$

Upvotes: 3

Related Questions