Script output:
ascii letters allowed in escape sequences: a, b, e, f, n, r, t, u, v, x, E, U
Non-escape letters: A, B, C, D, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, V, W,
X, Y, Z, c, d, g, h, i, j, k, l, m, o, p, q, s, w, y, z
NOTE: '\U' , '\x' , '\U' alone do not form escape sequences. \ , ' , " , ? and numbers are not taken into account because they are not alphabetic. '\e' is only GCC.
Sequences are created by compiling C code containing the string "\a\b...(for all ascii letters)...\z" and parsing the compilers:
#!/usr/bin/env python import re, string, subprocess, sys def _find_non_escape_chars(compiler="cc -xc -".split(), verbose=False): # prepare C code to compile test_code = 'char *s = "%s";' % ''.join('\\'+c for c in string.ascii_letters) # compile it p = subprocess.Popen(compiler, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) stdout, _ = p.communicate(test_code) if verbose: print stdout # find all non-escape characters return set(re.findall(r"'\\(.)'", stdout)) def is_escape_char(c, non_escape=_find_non_escape_chars()): """Whether `c` letter may be present in an escape sequence in C. >>> f = is_escape_char >>> f("a") True >>> f("g") False """ return c not in non_escape def main(): escape_chars = filter(is_escape_char, string.ascii_letters) print "ascii letters allowed in escape sequences:", ', '.join(escape_chars) print "Non-escape letters:", ', '.join( sorted(set(string.ascii_letters)-set(escape_chars))) if __name__=="__main__": import doctest; doctest.testmod() main()