Reputation: 3
This is my string: "Somestring8/9/0"
I need to get something like this: ['Somestring','8/9/0']
The moment I find a numeric char, I need to split the string to get: '8/9/0'
This my code:
stringSample = "GigabitEthernet8/9/0"
print re.findall(r'(\w+?)(\d+)', stringSample)[0]
('GigabitEthernet', '8')
But I'm getting this result What am I doing wrong?
I appreciate your help!!
Upvotes: 0
Views: 41
Reputation: 367
Try Using the re.split method to split your string in two, passing the maxsplit
parameter
re.split('(\w+?)([\d/]+)', stringSample, 1)
Upvotes: 0
Reputation: 23223
Your second regex group accepts only digits. Allow it to include forward slashes too.
stringSample = "GigabitEthernet8/9/0"
print re.findall(r'(\w+?)([\d/]+)', stringSample)[0]
# ('GigabitEthernet', '8/9/0')
Upvotes: 1