I have hostnames that do not have the same length/convention:
tor1er1
tor1x1ms1
For 'tor1er1', we can break it down:
'tor' = region
'1' = environment
'er' = type
'1' = number for the device
For 'tor1x1ms1' we can break it down:
'tor' = region
'1' = environment
'x1' = cross connect
'er' = type
'1' = number for the device
As you can see, there is an extra 'x1' for cross connect when it comes to tor1x1ms1. I'm trying to forumlate a regular expression to accommodate both type of strings. I've tried:
import re
hostname = 'tor1er1'
m = re.match(r"([a-zA-Z]+)([0-9]+)([a-zA-Z]+)([0-9]+)([a-zA-Z]+)([0-9]+)",hostname)
Because the length doesn't match the expression expected. I would like to be able to access each groups to pull the information. For example:
region = m.groups(1)
environment = m.groups(2)