正则匹配汉字文字

正则匹配汉字文字

1

2

3

4

5

6

7

8

9

10

11

12

13

import re

str='''

汉字文字

1234567890

abcdefghijklmnopqrstuvwxyz

-_+=!@#$%^&*()[]{};:"'<>,.?/|~ `

'''

ret = re.findall('[u4e00-u9fa5]',str)

# 匹配中文字符(双字节字符),汉字、中文标点符号

# ret = re.findall('[^x00-xff]',str)

print(ret)

print(''.join(ret))

  

  输出结果:

  

小结:

匹配汉字文字:

[u4e00-u9fa5]

匹配非汉字字符:

[^u4e00-u9fa5]

匹配双字节字符(汉字、中文标点符号等):

[^x00-xff]
原文地址:https://www.cnblogs.com/grj001/p/12223304.html