core (tools/common/regex): new ansiRemove method to remove ANSI escape codes from a string
This commit is contained in:
parent
09c40742d1
commit
828d1564fb
1 changed files with 10 additions and 0 deletions
|
|
@ -23,6 +23,8 @@ import re
|
|||
path_escape = {'%': '%25', '/': '%2F', '\\': '%5c'}
|
||||
path_escape_rev = {re.escape(v):k for k, v in path_escape.iteritems()}
|
||||
path_escape = {re.escape(k):v for k, v in path_escape.iteritems()}
|
||||
# thanks to Martijn Pieters (https://stackoverflow.com/a/14693789)
|
||||
RE_ANSI_REMOVE = re.compile(r'\x1b[^m]*m')
|
||||
|
||||
|
||||
def reJoin(exps):
|
||||
|
|
@ -60,3 +62,11 @@ def pathUnescape(string):
|
|||
@return (str, unicode): unescaped string
|
||||
"""
|
||||
return reSubDict(path_escape_rev_re, path_escape_rev, string)
|
||||
|
||||
def ansiRemove(string):
|
||||
"""Remove ANSI escape codes from string
|
||||
|
||||
@param string(basestr): string to filter
|
||||
@return (str, unicode): string without ANSI escape codes
|
||||
"""
|
||||
return RE_ANSI_REMOVE.sub('', string)
|
||||
|
|
|
|||
Loading…
Reference in a new issue