[Solved] How to split multiple string formats using regex and assigning its different groups to variable [closed]


You can use this code:

import re

domain = "collabedge-123.dc-01.com"
# preg_match("/^(collabedge-|cb|ss)([0-9]+).dc-([0-9]+).com$/", $domain, $matches);
regex = r"^(collabedge-|cb|ss)([0-9]+).dc-([0-9]+).com$"
res = re.match(regex,domain)
print(res.group(0))
print(res.group(1))
print(res.group(2))
print(res.group(3))

Output:

collabedge-123.dc-01.com
collabedge-
123
01

1

solved How to split multiple string formats using regex and assigning its different groups to variable [closed]