Regex match all except one word

Viewed 68

I have below strings for which I am building a regex

SGE_stats{metric_name="mainloop",panel_name="SGE Main Loop duration"} SGE_stats{metric_name="phyevensi_selected_cleared",panel_name="Facade processing"} SGE_stats{metric_name="total",panel_name="Events Processed"} SGE_stats{metric_name="BSW_cleared",panel_name="Proactive Interfaces"}

I built a regex /.*panel_name="([^"]*).*/ which matched below patterns
SGE Main Loop duration
Facade processing
Events Processed
Proactive Interfaces

I want to modify the regex to create two new expressions - One which matches SGE Main Loop duration and other which matches everything except SGE Main Loop duration
Can someone help me with this?
Thanks!!

1 Answers

With your shown samples and attempts, please try following regex. In both regex I am using \K option in which we can create regex and placing this in between will help us to forget its all previous matched values(though it consider them before \K) and then we can easily get only those values which are required.

1st scenario: Where it will look all strings apart from SGE Main Loop duration. Here is the Online demo for following regex.

panel_name="\K(?!SGE Main Loop duration)[^"]*

2nd scenario: Where it will only look for SGE Main Loop duration string. Here is the Online demo for following regex.

panel_name="\K(?:SGE Main Loop duration)(?="})
Related