For example I have string:
aacbbbqq
As the result I want to have following matches:
(aa, c, bbb, qq)
I know that I can write something like this:
([a]+)|([b]+)|([c]+)|...
But I think i's ugly and looking for better solution. I'm looking for regular expression solution, not self-written finite-state machines.
A repeat is an expression that is repeated an arbitrary number of times. An expression followed by '*' can be repeated any number of times, including zero. An expression followed by '+' can be repeated any number of times, but at least once.
The ?! n quantifier matches any string that is not followed by a specific string n.
The Match-zero-or-more Operator ( * ) This operator repeats the smallest possible preceding regular expression as many times as necessary (including zero) to match the pattern. `*' represents this operator. For example, `o*' matches any string made up of zero or more `o' s.
You can match that with: (\w)\1*
itertools.groupby
is not a RexExp, but it's not self-written either. :-) A quote from python docs:
# [list(g) for k, g in groupby('AAAABBBCCD')] --> AAAA BBB CC D
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