Skip to content

Instantly share code, notes, and snippets.

@onestarshang
Created March 3, 2015 08:36
Show Gist options
  • Select an option

  • Save onestarshang/7b374637051048fe947f to your computer and use it in GitHub Desktop.

Select an option

Save onestarshang/7b374637051048fe947f to your computer and use it in GitHub Desktop.
过滤字符串中的各种标点符号
# -*- encoding: utf-8 -*-
import string
import re
RE_PUCTUATION= '[\s+\.\!\/_,$%^*()+\"\']+|[+——!,。?、~@#¥%……&*()《》()&%¥#@!{}【】]+'
def filter_puctuation(ch_str):
str_res = ''
tmp = ch_str.decode('utf-8')
str_res = re.sub(RE_PUCTUATION.decode('utf8'), ''.decode('utf8'), tmp)
return str_res
if __name__ == '__main__':
ch_str = '中华人民共和国(北京)'
print filter_puctuation(ch_str)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment