python-正则表达式练习

1.匹配普通URL

^(http://)([a-z]+)\.([a-z]+)\.(com|cn|net|edu)(/(\w)+)+(.+)

python-正则表达式练习_第1张图片

2.匹配type返回的字符串中的类型

python-正则表达式练习_第2张图片

import re

re.match(r"^($","")
Out[5]: <_sre.SRE_Match object; span=(0, 36), match="">

m = re.match(r"^($","")

m.group()
Out[7]: ""

m.groups()
Out[8]: ('', 'builtin_function_or_method')

m.groups(2)
Out[9]: ('', 'builtin_function_or_method')

m.group(2)
Out[10]: 'builtin_function_or_method'

3.匹配月份

(^1[1-2])|(0?[1-9])

4.

 

你可能感兴趣的:(python-正则表达式练习)