Python正则匹配之原生字符串(待完善)

1. 匹配普通字符串


re.match('test','test').group() ##
输出:test
## 此时前后加‘r’结果都不会变

2. 匹配含有正则匹配规则的字符串

re.match('.','.').group()  #'.'
re.match('\.','.').group() #'.'
# 正则'.'可以匹配任意字符,'\\.'只匹配 '.'

re.match('\\\\d','\d').group() #'\\d'
# 'r'表明禁止转义,禁止正则的转义,禁止字符串转义
re.match('\\\\d',r'\d').group() #'\\d'
# r'\d'禁止字符串转义,r'\d'转义前为'\\d',正则规则为'\\\\d'
re.match(r'\\d',r'\d').group() #'\\d'
# 正则r'\\d'禁止正则转义,表明匹配字符串'\\d',即r'\d'
re.match('c:\\\\w\.txt','c:\\w.txt').group() # 'c:\\w.txt'

re.match('c:\\\\\\\\w\.txt',r'c:\\w.txt').group() # 'c:\\\\w.txt'

re.match(r'c:\\\\w\.txt',r'c:\\w.txt').group() # 'c:\\\\w.txt'
re.match('\\a','\a').group() # '\x07'
re.match('\\\\a',r'\a').group() # '\\a'
re.match(r'\\a',r'\a').group() # '\\a'
'\w' # '\\w'
r'\w' # '\\w'
'\\w' # '\\w'
r'\\w' # '\\\\w'
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值