正则表达式学习:
1 >>> import re 2 >>> re.search(r'FishC','I love FishC.com!') 3 <_sre.SRE_Match object; span=(7, 12), match='FishC'> 4 >>> "I love FishC.com!".find('FishC') 5 7 6 >>> re.search(r'.','I love FishC.com!') 7 <_sre.SRE_Match object; span=(0, 1), match='I'> 8 >>> re.search(r'fish.','I love FishC.com!') 9 >>> re.search(r'Fish.','I love FishC.com!') 10 <_sre.SRE_Match object; span=(7, 12), match='FishC'> 11 >>> re.search(r'\.','I love FishC.com!') 12 <_sre.SRE_Match object; span=(12, 13), match='.'> 13 >>> re.search(r'\d','I love 123 FishC.com!') 14 <_sre.SRE_Match object; span=(7, 8), match='1'> 15 >>> re.search(r'\d\d\d','I love 123 FishC.com!') 16 <_sre.SRE_Match object; span=(7, 10), match='123'> 17 >>> re.search(r'\d\d\d.\d\d\d.\d\d\d','192.168.111.123') 18 <_sre.SRE_Match object; span=(0, 11), match='192.168.111'> 19 >>> re.search(r'\d\d\d.\d\d\d.\d\d\d','192.168.1.1') 20 >>> re.search(r'[aeiou]',"I love FishC.com!") 21 <_sre.SRE_Match object; span=(3, 4), match='o'> 22 >>> re.search(r'[aeiouAEIOU]',"I love FishC.com!") 23 <_sre.SRE_Match object; span=(0, 1), match='I'> 24 >>> re.search(r'[a-z]',"I love FishC.com!") 25 <_sre.SRE_Match object; span=(2, 3), match='l'> 26 >>> re.search(r'[0-9]',"I love 123 FishC.com!") 27 <_sre.SRE_Match object; span=(7, 8), match='1'> 28 >>> re.search(r'[2-9]',"I love 123 FishC.com!") 29 <_sre.SRE_Match object; span=(8, 9), match='2'> 30 >>> re.search(r'ab{3}c','abbbc') 31 <_sre.SRE_Match object; span=(0, 5), match='abbbc'> 32 >>> re.search(r'ab{3}c','abbbbbbbc') 33 >>> re.search(r'ab{3-10}c','abbbbbbbc') 34 >>> re.search(r'ab{3,10}c','abbbbbbbc') 35 <_sre.SRE_Match object; span=(0, 9), match='abbbbbbbc'> 36 >>> re.search(r'ab{3,10}c','abbbbbbbc') 37 <_sre.SRE_Match object; span=(0, 9), match='abbbbbbbc'> 38 >>> re.search(r'[0-255]','188') 39 <_sre.SRE_Match object; span=(0, 1), match='1'> 40 >>> re.search(r'[0-2]\d\d|2[0-4]\d|25[0-5]','188') 41 <_sre.SRE_Match object; span=(0, 3), match='188'> 42 >>> 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])','192.168.1.1') 43 <_sre.SRE_Match object; span=(0, 11), match='192.168.1.1'>