Multiple group matches for one regex

I am parsing a log using python and need a quick fetch of values ​​from it

this is a simple equivalent regular expression and usage example

pat = re.compile("(1(2[3456]+2)+1)*")

This does not work as expected, only patmatch () returns only the last group of matches. groups ()

What is the simplest solution to such problems?

updated (because the wiki engine says that it uses the edit right, and does not create a new message):

I need duplicate matches, of course.

to_match="1232112542254211232112322421"

regex find needs to be applied twice recursively. I can bear it, but are there any options?

+5
source share
2 answers

, ( , ;-))

s = "123321124421125521"
pat = re.compile("(1(2[3456]+2)+1)")
print pat.findall(s)

findall(). :

[('123321', '2332'), ('124421', '2442'), ('125521', '2552')]

+1

, .

pat = re.compile("((1(2[3456]+2)+1)*)")

. http://www.regular-expressions.info/captureall.html

+1

All Articles