ANYCHAR = '.'; ESCAPE = '\\' REGIONA = '['; REGIONO = ']'; RANGE = '-'; COMPLEMENT = '^' GROUPA = '(' ; GROUPO = ')'; ALTERNATIVE = '|' PERHAPS = '?' ; STAR = '*'; JUST_ONE_and_STAR = '+' EXTENSION = '(?'; SKIPSTORE = '?:' def match_region(ch, pattern): """ region: a list of comparation chars and ranges in [] or [^]""" if pattern[1]==COMPLEMENT: booly=False; booln=True; i=2 else: booly=True; booln=False; i=1 while i < len(pattern): if pattern[i]==ESCAPE: if pattern[i+1]==ch: return booly else: i+=2 elif i 0: cc = pattern[k] if cc == ESCAPE: resu+=cc; resu+=pattern[k+1]; k+=2; continue if cc == GROUPA: lv+=1 elif cc == GROUPO: lv-=1 resu+=cc; k+=1 tokens.append(resu); i=k; kore=strip_groupattris(resu) if resu not in TokenListCache.keys(): TokenListCache[resu] = [] # groups are parsed to lists of token lists, each an alternative from '|' if kore[0] != GROUPA: for s in kore.split(ALTERNATIVE): TokenListCache[resu].append(parse_pattern(s, True)) else: TokenListCache[resu].append(parse_pattern(kore, True)) else: tokens.append(c); i+=1 if i