From fa13c68ebcec6e3dd6a3955f292224befffeb037 Mon Sep 17 00:00:00 2001 From: James Lu Date: Fri, 15 Jul 2016 23:44:25 -0700 Subject: [PATCH] SedRegex: work around "nothing to repeat" errors on Python < 2.7.6 Source: https://stackoverflow.com/questions/3675144/regex-error-nothing-to-repeat and https://bugs.python.org/issue18647 From: https://github.com/jlu5/SupyPlugins/commit/335fc6e3da685e1c899ca41f370383603924ce8f --- plugins/SedRegex/plugin.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/plugins/SedRegex/plugin.py b/plugins/SedRegex/plugin.py index acd7bb67c..153c431c6 100644 --- a/plugins/SedRegex/plugin.py +++ b/plugins/SedRegex/plugin.py @@ -44,9 +44,11 @@ try: except ImportError: _ = lambda x: x - +# Note: {0,2} is used for matching the flags instead of "*" to work around a Python bug in versions +# lower than 2.7.6: see https://stackoverflow.com/questions/3675144/regex-error-nothing-to-repeat +# and https://bugs.python.org/issue18647 SED_REGEX = re.compile(r"^(?:(?P.+?)[:,] )?s(?P[^\w\s])(?P.*?)(?P=delim)" - r"(?P.*?)(?:(?P=delim)(?P[gi]*))?$") + r"(?P.*?)(?:(?P=delim)(?P[gi]{0,2}))?$") class SedRegex(callbacks.PluginRegexp): """History replacer using sed-style regex syntax."""