retools¶
-
txttk.retools.
condense
(ss_unescaped)[source]¶ Given multiple strings, returns a compressed regular expression just for these strings
>>> condense(['she', 'he', 'her', 'hemoglobin']) 'he(moglobin|r)?|she'
-
txttk.retools.
is_solid
(regex)[source]¶ Check the given regular expression is solid.
>>> is_solid(r'a') True >>> is_solid(r'[ab]') True >>> is_solid(r'(a|b|c)') True >>> is_solid(r'(a|b|c)?') True >>> is_solid(r'(a|b)(c)') False >>> is_solid(r'(a|b)(c)?') False
-
txttk.retools.
is_packed
(regex)[source]¶ Check if the regex is solid and packed into a pair of parens
-
txttk.retools.
consolidate
(regex)[source]¶ Put on a pair of parens (with no catch tag) outside the regex, if the regex is not yet consolidated
-
txttk.retools.
danger_unpack
(regex)[source]¶ Remove the outermost parens
>>> unpack(r'(abc)') 'abc' >>> unpack(r'(?:abc)') 'abc' >>> unpack(r'(?P<xyz>abc)') 'abc' >>> unpack(r'[abc]') '[abc]'
-
txttk.retools.
unpack
(regex)[source]¶ Remove the outermost parens, keep the (?P...) one
>>> unpack(r'(abc)') 'abc' >>> unpack(r'(?:abc)') 'abc' >>> unpack(r'(?P<xyz>abc)') '(?P<xyz>abc)' >>> unpack(r'[abc]') '[abc]'
-
txttk.retools.
parallel
(regex_list, sort=False)[source]¶ Join the given regexes using r’|’ if the sort=True, regexes will be sorted by lenth before processing
>>> parallel([r'abc', r'def']) 'abc|def' >>> parallel([r'abc', r'd|ef']) 'abc|def' >>> parallel([r'abc', r'(d|ef)']) 'abc|d|ef' >>> parallel([r'abc', r'defg']) 'defg|abc'
-
txttk.retools.
concat
(regex_list)[source]¶ Concat multiple regular expression into one, if the given regular expression is not packed, a pair of paren will be add.
>>> reg_1 = r'a|b' >>> reg_2 = r'(c|d|e)' >>> concat([reg_1, reg2]) (a|b)(c|d|e)