【Pyton】【小甲鱼】正则表达式(一)

正则表达式学习:

 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'>

 

转载于:https://www.cnblogs.com/zhuzhubaoya/p/6720313.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值