Project

General

Profile

« Previous | Next » 

Revision 210

repl: Don't add whole-word regexp for inputs that already have regexp metachars

View differences:

repl
22 22
    reader = csv.reader(stream)
23 23
    repl_in, repl_out = reader.next()[:2]
24 24
    for row in reader:
25
        repls.append((r'\b'+row[0]+r'(?=(?:(?i)_id)?\b)', row[1]))
25
        in_, out = row[:2]
26
        if not re.match(r'[\\(?]', in_): # no special regexp chars
27
            in_ = r'\b'+in_+r'(?=(?:(?i)_id)?\b)' # match whole word
28
        repls.append((in_, out))
26 29
    stream.close()
27 30
    def repl_all(str_):
28 31
        for repl, with_ in repls: str_ = re.sub(repl, with_, str_)

Also available in: Unified diff