Created
March 3, 2015 08:36
-
-
Save onestarshang/7b374637051048fe947f to your computer and use it in GitHub Desktop.
过滤字符串中的各种标点符号
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # -*- 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