import re
l ="beautiful is better than uqly."
matches = re.findall("beautiful",l)print(matches)['beautiful']
import re
l ="beautiful is better than uqly."
matches = re.findall("Beautiful",l,re.IGNORECASE)#可以忽略大小写print(matches)
匹配起始位置
import re
zen ="""Although never is
often better than
*right* now.
If the implementation
is hard to explain,
it's a bad idea.
If the implementation
is easy to explain,
it may be a good
idea. Namesapces
are one honking
great idea -- let's
do more of those!
"""
m = re.findall("^if",#小箭头表示只有在行的其实位置时才匹配
zen,
re.MULTILINE)print(m)
匹配多个字符
import re
zen ="two too"
m = re.findall("t[wo]o",#第一个字符为t,中间为o 或 w 最后是o 的才匹配
zen
简单匹配import rel = "beautiful is better than uqly."matches = re.findall("beautiful",l)print(matches)['beautiful']import rel = "beautiful is better than uqly."matches = re.findall("Beautiful...