代码要多敲 注释邀清晰

虽然简单 敲一敲 增长不少

可以为以后的工作提供一些方便

#反义的查找方法
import re

#匹配任意不是字母,数字,下划线,汉字的字符
pattern = re.compile(r'\W')
s = pattern.findall(';')
print(1,s)#1 [';']

#匹配任意不是空白符的字符 结果形成列表
pattern = re.compile(r'\S')
s = pattern.findall('  wode ')
print(2,s)#2 ['w', 'o', 'd', 'e']

#匹配任意非数字的字符 包括空白符
pattern = re.compile(r'\D')
s = pattern.findall(' sd31 ')
print(3,s)#3 [' ', 's', 'd', ' ']

#匹配除了a意外的任意 字符
pattern = re.compile(r'[^a]')
s = pattern.findall('afaa bbb')
print(4,s)#4 ['f', ' ', 'b', 'b', 'b']

#匹配除了abcde这几个字母以外的任意字符
pattern = re.compile(r'[^abcde]')
s = pattern.findall('sfdafg')
print(5,s)#5 ['s', 'f', 'f', 'g']

#匹配除了123 abc这几个字符以外的任意字符
pattern = re.compile(r'[^(123|abc)]')
s = pattern.findall('sdda25')
print(6,s)#6 ['s', 'd', 'd', '5']

 

相关文章:

  • 2022-03-04
  • 2022-12-23
  • 2021-12-15
  • 2022-12-23
  • 2022-01-06
  • 2021-10-20
猜你喜欢
  • 2021-06-29
  • 2021-05-21
  • 2021-09-15
  • 2021-12-04
  • 2022-12-23
相关资源
相似解决方案