With RegEx in a pattern, how do you extract multiple values?

cloudyrobert
Kilo Guru

Could someone please provide an example of using the parse file operation with RegEx to run multiple RegEx expressions in order to build a table? For example, how could I use RegEx to pull back multiple values from the config.xml file on the MID server host in a single Parse File step and store them in a table of variables?

The docs site says to enclose each expression in parentheses, but I've not been able to get that to work.

"To extract multiple values, define several expressions enclosing each expression into parentheses."

https://docs.servicenow.com/bundle/london-it-operations-management/page/product/service-mapping/task...

11 REPLIES 11

vNick
ServiceNow Employee
ServiceNow Employee

If you have an example it could help, but you could also try ensuring you have ".*" between the values you are trying to evaluate for... for example:

\[\{metricName\=(.+?)\,.*metricValue\=(.+?)\}\]

The above regex will get the 2 values for metricName and metricValue and ignore everything in between.  It will only get the "(.+?)" values

robertgeen
Tera Guru

Keep in mind the out of the box regex is not global (e.g. it doesn't use the /g flag) and as such it will only capture the first occurrence that matches your regex. If you have multiple values on many lines you want to match then it's best to use the delimiter strategy and break on a custom line value. Hope this helps.

Asi Garty
ServiceNow Employee
ServiceNow Employee

find_real_file.png

cloudyrobert
Kilo Guru

Here's a more specific example. I realize there may be other ways of accomplishing this, but I'd like to understand how this one works as the documentation makes this sound possible.

Let's say I want to build a variable table mid_config with the variables name and threads. I can match the value for name with this:

find_real_file.png

I can match the value for threads with this:

find_real_file.png

Based on the documentation, I would think that in order to match the two, I would need to provide both expressions with each of them enclosed in parentheses. Perhaps, there is some delimiter that should separate the two. This does not work (the second expression is the same as the one in the image above):

find_real_file.png