>>>import re
>>> example ='ShanDong Institute of Business and Technology'>>> pattern = re.compile(r'\bB\w+\b')#查找以B开头的单词>>> pattern.findall(example)#使用正则表达式对象的findall()方法['Business']>>> pattern = re.compile(r'\w+g\b')#查找以字母g结尾的单词>>> pattern.findall(example)['ShanDong']>>> pattern = re.compile(r'\b[a-zA-Z]{3}\b')#查找3个字母长的单词>>> pattern.findall(example)['and']>>> s ='ab134ab98723jafjweoruiagab'>>> m = re.search(r'((ab).*){2}.*(ab)', s)#在s中查找ab的第3次出现>>> m.group(3)'ab'>>> m.span(3)(24, 26)>>> s[24:]'ab'>>> pattern.match(example)#从字符串开头开始匹配,失败返回空值>>> pattern.search(example)#在整个字符串中搜索,成功<_sre.SRE_Match object; span=(31, 34), match='and'>>>> pattern = re.compile(r'\b\w*a\w*\b')#查找所有含有字母a的单词>>> pattern.findall(example)['ShanDong', 'and']>>> text ="He was carefully disguised but captured quickly by police.">>> re.findall(r"\w+ly", text)#查找所有以字母组合ly结尾的单词['carefully', 'quickly']