Anıl Baki Durmuş
Anıl Baki Durmuş

Reputation: 43

Regex get all strings after first pipe

I need to get strings between first pipe to third pipe.

Eg given

DOWN | Origin - test-pd-2 | Pool - test-pd | TCP timeout occurred

match:

Origin - test-pd-2 | Pool - test-pd

I tried this, but it didn't work:

.*\\|(.*)\|

Upvotes: 3

Views: 537

Answers (3)

The fourth bird
The fourth bird

Reputation: 163217

Using a capture group and a negated character class, you might also use

^[^|]*\| ([^|]+\|[^|]*[^\s|])

Regex demo

Upvotes: 1

Bohemian
Bohemian

Reputation: 424983

After a pipe |, match non-pipes, pipe, non-pipes:

(?<=\| )[^|]+\|[^|]+[^| ]

See live demo.

The entire match is your target

Upvotes: 0

c0bra
c0bra

Reputation: 1080

^.+\|(.+\|{1}.+)\|.+$

regex101

Note that backslashes might need to be escaped depending on the language you are using.

Upvotes: 0

Related Questions