1.获取字符串中的中文
a = "hello 404 word 世界 99 胜利"
data_list = [i for i in a.split(' ') if i>= '\u4e00' and i<= '\u9fff' ]
输出结果是: ['世界', '胜利']
2. 获取字符产中的数字
data = [i for i in a.split(' ') if i.isdigit()]
输出结果是: ['404', '99']
3. 获取字符串中的字母, 其中中文也属于字母:
data = [i for i in a.split(' ') if i.isalpha()]
输出结果: ['hello', 'word', '世界', '胜利']
4. 正则匹配中文字符串
a = "not 404 found 张三 99 深圳"
d = re.findall(r'[^a-zA-Z0-9]+', a.replace(' ', ''))
输出结果是: ['张三', '深圳']
Get Chinese characters, letters, or numbers in a string
Guess you like
Origin blog.csdn.net/xxy_yang/article/details/104821371
Recommended
Ranking