Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Regex get all strings after first pipe

Tags:

regex

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:

.*\\|(.*)\|
like image 592
Anıl Baki Durmuş Avatar asked May 13 '26 20:05

Anıl Baki Durmuş


1 Answers

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

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

Regex demo

like image 82
The fourth bird Avatar answered May 15 '26 11:05

The fourth bird