Active IQ Unified Manager Discussions

Regular Expression problem

luetfi
4,034 Views

Hi

I was doing a PoC and had problem with RegExp for extracting host names from zone names. there are three types of zone names in my customer environment:

- Z_HostName_hba_1_blah

- Zone_HostName_hba_2

- Zone_P565_Hostname_hba_2_blah

I was using as regexp (.*?)_(.*?)_(.*?)

This is working for some zone names but for some zones/hosts (even they are looking similar to zone names which are working) it doesn't work.

What am I doing wrong? Is there any tool to create regexps easily especially if customer has any rules for zone names?

Thanks

Lutfi

1 REPLY 1

francoi1
4,034 Views

Assuming that in each case the "hostname" part you want to extract:

".*?_(.*?)_.*?" will do it for strings with the form "<something>_HostName_<anything>"


Zone_.+?_(.+?)_.*+ will catch "Zone_<something>_Hostname_<anything>"

In case you haven't seen it, a way to test your regexp it to use the GUI: from the "Automatic Host Resolution Regexp Wizard" window, once you've added an expression click on the "..." small button at the right of the "Regexp" line to access the "Regular Expression Editor" to test live your expression, it's handy to figure out what's the output.


There's also a link to an HTML help page with all regular-expression you can use.

Hope that helps.

/fx


Public