Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Split regular expression into 2 capture groups

Ok, my previous questions were answered ... I have one more, this one is more difficult for me...

^([A-Za-z]+\.[A-Za-z0-9_-]+\.domain\.com)$

Right now this expression produces only 1 capture group as noted with ^() ; How would I do 2 capture groups for this URL? (for IIS regular expression rewrite)

like image 874
Jason Avatar asked Jan 17 '23 15:01

Jason


1 Answers

You can do this by enclosing the relevant portions like so:

text    = "city.state.domain.com"
pattern = "^([^\.]+).([^\.]+).([^\.]+).([^\.]+)$"
match   = re.match(pattern, text)
match.groups()
# Returns: [ 'city', 'state', 'domain', 'com' ]
like image 92
Stephen Gross Avatar answered Jan 25 '23 17:01

Stephen Gross