《python核心编程》课后题第二版第十五章463页

15-1.识别下列字符串:bat、bit、but、hat、hit或hut。

import re

s = raw_input('Enter>> \n')
pat = '.*?([bh][aiu]t).*'
m = re.match(pat, s)
if m:
    print m.group(1)
else:
    print 'no match'

15-2.匹配用一个空格分隔的任意一对单词,比如名和姓。

import re

s = raw_input('Enter>> \n')
pat = '.*?(\w+ \w+).*'
m = re.match(pat, s)
if m:
    print m.group(1)
else:
    print 'no match'

15-3.匹配用一个逗号和一个空格分开的一个单词和一个字母。例如英文人名中的姓和名的首字母。

没看懂

15-4.匹配所有合法的python标识符。

不知道什么是python标识符

15-6.匹配简单的以www.开头,以.com结尾的web域名。

注:

1、中间少了几章实在是看不懂,特别是类那一章,等之后看明白了再补上。

2、本文主要参考晓美焰的百度博文,http://hi.baidu.com/deathanybody/item/800524567a2c6d07da16359b。

原文地址:https://www.cnblogs.com/alexkh/p/2891057.html