From 7f21e5c9d0bda1d95fcf5a364b4e52862474f337 Mon Sep 17 00:00:00 2001 From: vwyu Date: Fri, 11 Jan 2019 00:35:05 +0900 Subject: [PATCH] Escape literal special characters in sre_to_string method. --- exrex.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/exrex.py b/exrex.py index 37d2b3d..b8f4aa2 100644 --- a/exrex.py +++ b/exrex.py @@ -306,7 +306,8 @@ def sre_to_string(sre_obj, paren=True): prefix = '^' ret += u'[{0}{1}]'.format(prefix, sre_to_string(i[1], paren=paren)) elif i[0] == sre_parse.LITERAL: - ret += unichr(i[1]) + u = unichr(i[1]) + ret += u if u not in sre_parse.SPECIAL_CHARS else '\\{0}'.format(u) elif i[0] == sre_parse.CATEGORY: ret += REVERSE_CATEGORIES[i[1]] elif i[0] == sre_parse.ANY: