def tokenize(s):
    keywords = {'IF', 'THEN', 'ENDIF', 'FOR', 'NEXT', 'GOSUB', 'RETURN'}
token_specification = [('NUMBER', '\\d+(\\.\\d*)?'), ('ASSIGN', ':='), (
    'END', ';'), ('ID', '[A-Za-z]+'), ('OP', '[+*\\/\\-]'), ('NEWLINE',
    '\\n'), ('SKIP', '[ \\t]')]
Efficiently match multiple regexes in Python