python的内置正则表达式学习与理解 1

Python正则表达式速查
本文介绍Python中正则表达式的使用方法,包括常见元字符的含义及用途,如. ^ $等,并详细解释了.d、.s、.w等特殊字符的匹配规则。

首先需要import re

python自带正则表达式是一组c语言二进制码接口,因此速度较快。


正则表达式里面有一些特殊字符——matacharacters,包括


. ^ $ * + ? { } [ ] \ | ( )

[  ] 用来指明一类数据,[a-c],[abc],都是用来匹配a,b,c中任何一个字母

[  ] 中的元字符失去了其魔力,而变成了一个普通的字符

\   让 元字符失去魔力的另一个方法,但也给一些普通字符与魔力

\d
Matches any decimal digit; this is equivalent to the class [0-9].
\D
Matches any non-digit character; this is equivalent to the class [^0-9].
\s
Matches any whitespace character; this is equivalent to the class [ \t\n\r\f\v].
\S
Matches any non-whitespace character; this is equivalent to the class [^ \t\n\r\f\v].
\w
Matches any alphanumeric character; this is equivalent to the class [a-zA-Z0-9_].
\W
Matches any non-alphanumeric character; this is equivalent to the class [^a-zA-Z0-9_]

.     用于匹配除newline以外的任何东西

需要匹配newline的时候,试用re.dotall



评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值