I'm parsing a log with python and need quick fetch some values from it
this is the simple equivalent regex and usage example
pat = re.compile("(1(2[3456]+2)+1)*")
It doesn't work as expected, only the last match group is returned by pat.match().groups()
What is the simplest solution for such problems?
updated (as wiki engine says to use edit rather than creating new post):
I need repeated matches, of course.
to_match="1232112542254211232112322421"
regex find need to be applyed twice recursively. I can bear it, but is there any options?
Ok, try this (but only after you learned how to accept answers ;-) )
s = "123321124421125521"
pat = re.compile("(1(2[3456]+2)+1)")
print pat.findall(s)
remove the quantifier and use instead findall()
. This will result in this list:
[('123321', '2332'), ('124421', '2442'), ('125521', '2552')]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With