diff --git a/python/phonenumbers/phonenumberutil.py b/python/phonenumbers/phonenumberutil.py index 0fc3f598..f40f5ccb 100644 --- a/python/phonenumbers/phonenumberutil.py +++ b/python/phonenumbers/phonenumberutil.py @@ -248,7 +248,10 @@ # which nets down to: >=1 non-Number, non-Letter, non-# characters at string end # In Python Unicode regexp mode '(?u)', the class '[^#\w]' will match anything # that is not # and is not alphanumeric and is not underscore. -_UNWANTED_END_CHARS = u(r"(?u)(?:_|[^#\w])+$") +# The negative lookbehind only lets a match start at the beginning of a run +# of these characters; without it, search() retries from every position in a +# run that is not at the end of the string, which is quadratic in its length. +_UNWANTED_END_CHARS = u(r"(?u)(?