我想從字符串中篩選出不一致的字符。正則表達式幫助python與alphanumaric
目前我有this..in蟒蛇
name = re.sub('([^a-zA-Z0-9 -\'!$&])',' ', name)
但我想包括諸如「()」括號「/」反斜線和斜槓。不知何故,它不起作用。 任何人都可以看看,請..
我想從字符串中篩選出不一致的字符。正則表達式幫助python與alphanumaric
目前我有this..in蟒蛇
name = re.sub('([^a-zA-Z0-9 -\'!$&])',' ', name)
但我想包括諸如「()」括號「/」反斜線和斜槓。不知何故,它不起作用。 任何人都可以看看,請..
name = re.sub('([^a-zA-Z0-9\[\]\(,\)\+\/ \\-\'!$&])',' ', name)
非正則表達式的解決方案
accepted = '''!$*()\/.,>-_=+<:;'"?|'''
allowed = string.digits + string.letters + accepted
filter(allowed.__contains__, name)
這將過濾字符串名非字母數字字符和否定來篩選列出的字符在接受。
找到正則表達式... – 2013-03-09 09:56:50
如果您找到了答案,然後張貼它並接受它。 – Volatility 2013-03-09 09:59:08