2012-08-08 02:37 PM
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:
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?
2012-08-09 03:07 AM
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.