I am reading a book and they provide an example of how to match a given string with regular expressions. Here is their example:
b*(abb*)*(a|∊) - Strings of a's and b's with no consecutive a's.
Now I've tried converting it to python like so:
>> p = re.compile(r'b*(abb*)*(a|)') # OR
>> p = re.compile(r'b*(abb*)*(a|\b)')
# BUT it still doesn't work
>>> p.match('aa')
<_sre.SRE_Match object at 0x7fd9ad028c68>
My question is two-fold:
- What is the equivalent of epsilon in python to make the above example work?
- Can someone explain to me why theoretical or standard way of doing regular expressions does not work in python? Might it have something to do with the longest vs shortest matching?
Clarification: For people asking what standard regex is - it is the formal language theory standard: http://en.wikipedia.org/wiki/Regular_expression#Formal_language_theory