In [97]:
import sys
sys.path.append('/Users/thatch/code/sre_yield_thatch')
import sre_yield
reload(sre_yield)
Out[97]:
<module 'sre_yield' from '/Users/thatch/code/sre_yield_thatch/sre_yield.pyc'>
In [98]:
v = sre_yield.AllStrings('[01]{1,5}')
len(v)
Out[98]:
62
In [99]:
v[0]
Out[99]:
'0'
In [100]:
print list(v)
['0', '1', '00', '01', '10', '11', '000', '001', '010', '011', '100', '101', '110', '111', '0000', '0001', '0010', '0011', '0100', '0101', '0110', '0111', '1000', '1001', '1010', '1011', '1100', '1101', '1110', '1111', '00000', '00001', '00010', '00011', '00100', '00101', '00110', '00111', '01000', '01001', '01010', '01011', '01100', '01101', '01110', '01111', '10000', '10001', '10010', '10011', '10100', '10101', '10110', '10111', '11000', '11001', '11010', '11011', '11100', '11101', '11110', '11111']

In [101]:
v = sre_yield.AllMatches(r'([\'"])((\\\\|\\.|[^\\])*?)\1', max_count=10)
In [102]:
len(v)
---------------------------------------------------------------------------
OverflowError                             Traceback (most recent call last)
<ipython-input-102-89a6b4061ae0> in <module>()
----> 1 len(v)

OverflowError: long int too large to convert to int
In []:
v.__len__()
In []:
for i in range(10):
    print v[i].group(0)
In []:
for i in range(10):
    print repr(v[i].group(0))
In []:
v[2].group(0)
In []:
v[2].group(1), v[2].group(2)
In []:
r'"abc\\\n\0"' in v
# r'([\'"])((\\\\|\\.|[^\\])*?)\1'
In []:
v = sre_yield.AllStrings('.*')
In []:
len(v)
In []:
v.__len__()
In []:
# This used to be taken literally from the parse tree.
print sre_yield.MAX_REPEAT_COUNT
In []:
import re, _sre
reload(re) # clears cache, yes there are other ways to show the tree
re.compile('.*', re.DEBUG)
re.compile('.*?', re.DEBUG)
print _sre.MAXREPEAT
In []:
import math
def show_size(n):
    print int(math.ceil(math.log(n.__len__(), 10))), "decimal digits"
    print int(math.ceil(math.log(n.__len__(), 256))), "bytes"
In []:
show_size(v)
In []:
show_size(sre_yield.AllStrings('.*.*.*'))
In []:
show_size(sre_yield.AllStrings('(?:(?:[a-z]{,100}){,100}){,100}'))
In []: