源代码如下:
import re
print(re.search(r'[aeiou]', 'I love JingJing ~5~2~1.'))
print(re.search(r'[aeiouAEIOU]', 'I love JingJing ~5~2~1.'))
print(re.search(r'[a-z]', 'I love JingJing ~5~2~1.'))
print(re.search(r'[a-e]', 'I love JingJing ~5~2~1.'))
print(re.search(r'([0-9].)+', 'I love JingJing ~5~2~1.'))
print(re.search(r'ab{3}c', 'abbbc'))
print(re.search(r'ab{3}c', 'abbbbbc'))
print(re.search(r'ab{3,10}c', 'abbbbbbc'))
print(re.search(r'[0-255]', '188'))
print(re.search(r'[01]\d\d|2[0-4]\d|25[0-5]', '128'))
print(re.search(r'(([01]\d\d|2[0-4]\d|25[0-5])\.){3}([01]\d\d|2[0-4]\d|25[0-5])', '196.168.1.1'))
print(re.search(r'(([01]{0,1}\d{0,1}\d|2[0-4]\d|25[0-5])\.){3}([01]{0,1}\d{0,1}\d|2[0-4]\d|25[0-5])', '196.168.1.1'))
运行结果如下:
<re.Match object; span=(3, 4), match='o'> <re.Match object; span=(0, 1), match='I'> <re.Match object; span=(2, 3), match='l'> <re.Match object; span=(5, 6), match='e'> <re.Match object; span=(17, 23), match='5~2~1.'> <re.Match object; span=(0, 5), match='abbbc'> None <re.Match object; span=(0, 8), match='abbbbbbc'> <re.Match object; span=(0, 1), match='1'> <re.Match object; span=(0, 3), match='128'> None <re.Match object; span=(0, 11), match='196.168.1.1'>
|