Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

REGEX to find STRING between two values

I have a string being received from a monitoring system, the string contains 3 variables that I am interested in the variables are pre/post fixed with c=VAR1; e=VAR2; s=VAR3; so I want to grab the text in between for example c= ; but am having limited success, these are a few of the REGEXs I have tested with:

c=([^;]+);
.+c=(.+);.+
(?<=c=\()(.*?)(?=\;*\))
c=(.*);

A full alert string would look similar to:

alert c=Vari Able1; e=Vari Able2; s=Vari Able3;

But none seem to return in the way I would expect.

Any help is much appreciated.

Thanks!

like image 785
Andrew Reynolds Avatar asked Jul 30 '26 22:07

Andrew Reynolds


1 Answers

You can use something like:

(\w+)=([^;]+)

Which would grab all values (key and value), but if you're after only the c value:

c=([^;]+)

Should capture everything between the = and ; (([^;]+) captures every character that's not a semi-colon, repeated 1 or more times.).

like image 125
Brad Christie Avatar answered Aug 02 '26 14:08

Brad Christie



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!