Active IQ Unified Manager Discussions
I have a problem with RegExp for extracting host names from switch alias.
switchalias : abcdtsm01_aixfcs3
Hostname : abcd-tsm01
Expression used: ([a-zA-Z0-9]*)_([^_]+).* \1 it will capture " abcdtsm01" which is wrong
How can i add "-" in the middle to show as abcd-tsm01.
See The Solution
Are all the strings the same, meaning four letters and then - or are they different.
regex is to pull out what you need, but string manipulation is different
View solution in original post
Few Hostnames same four letters and then "-" .
If it is always 4 characters, dash, ...
This regular expression will:
Look for exactly 4 alphanumeric case insensitive characters - this will be \1 aka string 1
Look for at least a 2 alphanumeric case insensitive string that follows - this will be \2 aka string 2
Look for a dash, follow by more characters
When this pattern matches, you will have 2 strings
If you change the format for this rule from "\1" to "\1-\2" , you will build a concatenated string of "string1-string2"
I would characterize this regexp as fairly risky - it is only worth trying if ALL of your hosts are named this way.
If this pattern only applies for TSM hosts, you will want to write a narrower regexp
Are all the hosts exactly 4letters-xxxxx?
Basically, you have an alphanumeric string - how do you know where the dash is supposed to be?
Join our Discord Community