import re pattern = re.compile(r'd+') s = pattern.search('hello 123456 789') print(s.group()) s = pattern.findall('hello 13456 789') print(s) # str = 'I love You!' # def daoxuprint(str): # i = len(str)-1 # while i >= 0: # print(str[i],end='') # i -= 1 # #方法二 # pattern = re.compile(r'.') # s = pattern.findall(str) # print(s) # for item in s: # # print(item) # daoxuprint('love') #举例2 I love You # pattern = re.compile(r'(w+)(!?)') # s = pattern.findall(str) # print(s,type(s)) # for item in s: # for i in item: # if i == '': # daoxuprint(' ') # else: # daoxuprint(i) # #. 是刚需必须有 d+ 必须一个或多个数字 # pattern = re.compile(r'd+.d*') # # d = pattern.findall('3.141592653 PI 100 10001.11 3. .8 0.9') # print(d)