finished StripByRegex.py

This commit is contained in:
pezy_mbp
2017-06-15 01:04:56 +08:00
parent a826e89cde
commit c201c6b3bf

View File

@@ -10,5 +10,14 @@ the function will be removed from the string.
'''
from re import compile
def stripInRegexWay()
def stripInRegexWay(string, bad=" "):
strip_regex = compile(r'(^[{0}]*)(.*?)([{1}]*$)'.format(bad, bad))
return strip_regex.search(string).group(2)
assert stripInRegexWay(' dsadas ') == 'dsadas'
assert stripInRegexWay(' dasd dsd ') == 'dasd dsd'
assert stripInRegexWay('addsada', 'ad') == 's'
assert stripInRegexWay('adsradsnads', 'ads') == 'radsn'