Divida la expresión regular en 2 grupos de captura

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)

preguntado el 30 de enero de 12 a las 19:01

What do you want to grab from the string? Post an example, and what you want to get out of it. -

Ok, you haven't answered my question. Please post an example of the text to parse, and explain which portions of it you want to match. -

oh sry. --- I want to grab ie. silverspring.md.domain.com and capture group example: {c:1} silverspring {c2} md -

1 Respuestas

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' ]

Respondido 13 Feb 18, 17:02

Note, BTW, that I made the simplifying assumption that you can have any possible values between the '.' characters. Also, in the future, you can always just split() on '.'. - Stephen Gross

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.