Active IQ Unified Manager Discussions

RegExp for extracting host names from switch alias

ameegama
3,603 Views

Hi

 

I have a  problem with RegExp for extracting host names from  switch alias.

Details:

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.

 

 

1 ACCEPTED SOLUTION

JGPSHNTAP
3,587 Views

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

4 REPLIES 4

JGPSHNTAP
3,588 Views

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

ameegama
3,572 Views

Hi

Few Hostnames  same four letters and then  "-" . 

ostiguy
3,555 Views

If it is always 4 characters, dash, ...

 

([A-Za-z0-9]{4})([A-Za-z0-9]+)-.*

 

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

ostiguy
3,578 Views

Are all the hosts exactly 4letters-xxxxx?

 

Basically, you have an alphanumeric string - how do you know where the dash is supposed to be?

Public