mirror of https://github.com/TwoWater/Python
26 lines
599 B
Python
26 lines
599 B
Python
#!/usr/bin/env python3
|
||
# -*- coding: UTF-8 -*-
|
||
|
||
import re
|
||
|
||
a = 'uav_ubv_ucv_uwv_uzv_ucv_uov&123-456-789'
|
||
|
||
# 概括字符集
|
||
|
||
# \d 相当于 [0-9] ,匹配所有数字字符
|
||
# \D 相当于 [^0-9] , 匹配所有非数字字符
|
||
findall1 = re.findall('\d', a)
|
||
findall2 = re.findall('[0-9]', a)
|
||
findall3 = re.findall('\D', a)
|
||
findall4 = re.findall('[^0-9]', a)
|
||
print(findall1)
|
||
print(findall2)
|
||
print(findall3)
|
||
print(findall4)
|
||
|
||
# \w 匹配包括下划线的任何单词字符,等价于 [A-Za-z0-9_]
|
||
findall5 = re.findall('\w', a)
|
||
findall6 = re.findall('[A-Za-z0-9_]', a)
|
||
print(findall5)
|
||
print(findall6)
|