Search code examples
regexzabbix

Get value with regex


In zabbix I'm monitoring a couple of processes that have same name but stories in different folders. So I'm trying to create discovery rule to get info about all processes with wmi. Problem is: I need get folder name from string to create correct zabbix item. Can you please help me create correct regex formula to get folders?

For example: there are 3 strings

%E:%test%dc1%dc.exe%
%E:%test%test2%dc2%dc.exe%
%E:%test%test2%test3%dc3%dc.exe%

From each string I need words

dc1
dc2
dc3

Solution

  • Using % as a delimiter, this will get the second to last token in your string

    [^%]+(?=%[^%]*%$)
    

    enter image description here

    Example