Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wrong regexp for click.unstyle() #1216

asvetlov opened this issue Feb 1, 2019 · 1 comment

Wrong regexp for click.unstyle() #1216

asvetlov opened this issue Feb 1, 2019 · 1 comment


Copy link

@asvetlov asvetlov commented Feb 1, 2019

The function uses strip_ansi() which in turn depends on _ansi_re regex:

The pattern is: r'\033\[((?:\d|;)*)([a-zA-Z])'.
It is a little not full: \033[?25l and \033[?25h ANSI sequences used by cursor show/hide are not covered by the pattern.

I've changed it to r'\033\[([;\?0-9]*)([a-zA-Z])', it fixes my problem.

@jcrotts jcrotts added this to the 8.0 milestone May 6, 2019
@jcrotts jcrotts added the enhancement label May 6, 2019

This comment has been minimized.

Copy link

@sekenned sekenned commented May 6, 2019


>>> import re
>>> #
... _ansi_re = re.compile(r'\033\[((?:\d|;)*)([a-zA-Z])')
>>> #
... def strip_ansi(value):
...     return _ansi_re.sub('', value)
>>> test_string = "\033[?25leggs and spam\033[?25h"
>>> strip_ansi(test_string)
'\x1b[?25leggs and spam\x1b[?25h'
>>> # suggested update
... _ansi_re = re.compile(r'\033\[([;\?0-9]*)([a-zA-Z])')
>>> strip_ansi(test_string)
'eggs and spam'

Will submit PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
4 participants
You can’t perform that action at this time.