IGNORECASE errors in Python's re.Scanner?
Question: There is hidden but well known
[functionality](http://code.activestate.com/recipes/457664-hidden-scanner-
functionality-in-re-module/) in re module

    
    
    import re
    
    def s_ident(scanner, token): return token
    def s_operator(scanner, token): return "op%s" % token
    def s_float(scanner, token): return float(token)
    def s_int(scanner, token): return int(token)
    
    scanner = re.Scanner([
        (r"[a-zA-Z]\w*", s_ident),
        (r"\d+\.\d*", s_float),
        (r"\d+", s_int),
        (r"=|\+|-|\*|/", s_operator),
        (r"\s+", None),
        ])
    
    print scanner.scan("Sum = 3*foo + 312.50 + bar")
    # (['Sum', 'op=', 3, 'op*', 'foo', 'op+', 312.5, 'op+', 'bar'], '')
    

I want to use IGNORECASE flag here but it seems it does not work:

    
    
    import re
    
    def s_ident(scanner, token): return token
    def s_operator(scanner, token): return "op%s" % token
    def s_float(scanner, token): return float(token)
    def s_int(scanner, token): return int(token)
    
    scanner = re.Scanner([
        (r"(?i)[a-z]\w*", s_ident),
        (r"\d+\.\d*", s_float),
        (r"\d+", s_int),
        (r"=|\+|-|\*|/", s_operator),
        (r"\s+", None),
        ])
    
    print scanner.scan("Sum = 3*foo + 312.50 + bar")
    # ([], 'Sum = 3*foo + 312.50 + bar')
    

Is it a issue of the Scanner or error in my code? Is it possible to implement
non-case-sensitive matching using Scanner?

This issue was initially reproduced on Python 2.7.9.

Expected value: (['Sum', 'op=', 3, 'op*', 'foo', 'op+', 312.5, 'op+', 'bar'],
'')

Actual value: ([], 'Sum = 3*foo + 312.50 + bar')


Answer: You can pass the `flags` parameter to the constructor.

    
    
    scanner = re.Scanner([
        (r"[a-z]\w*", s_ident),
        (r"\d+\.\d*", s_float),
        (r"\d+", s_int),
        (r"=|\+|-|\*|/", s_operator),
        (r"\s+", None),
        ], flags=re.IGNORECASE)
    

Source for `Scanner`:
<https://github.com/python/cpython/blob/master/Lib/re.py#L345>

