python正则表达式(三)
表示边界

示例1:$
需求:匹配163.com的邮箱地址
#coding=utf-8 import re # 正确的地址
ret = re.match("[\w]{4,20}@163\.com", "xiaoWang@163.com")
ret.group() # 不正确的地址
ret = re.match("[\w]{4,20}@163\.com", "xiaoWang@163.comheihei")
ret.group() # 通过$来确定末尾
ret = re.match("[\w]{4,20}@163\.com$", "xiaoWang@163.comheihei")
ret.group()

示例2: \b
>>> re.match(r".*\bver\b", "ho ver abc").group()
'ho ver' >>> re.match(r".*\bver\b", "ho verabc").group()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'NoneType' object has no attribute 'group' >>> re.match(r".*\bver\b", "hover abc").group()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'NoneType' object has no attribute 'group'
示例3:\B
>>> re.match(r".*\Bver\B", "hoverabc").group()
'hover' >>> re.match(r".*\Bver\B", "ho verabc").group()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'NoneType' object has no attribute 'group' >>> re.match(r".*\Bver\B", "hover abc").group()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'NoneType' object has no attribute 'group' >>> re.match(r".*\Bver\B", "ho ver abc").group()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'NoneType' object has no attribute 'group'
匹配分组

示例1:|
需求:匹配出0-100之间的数字
#coding=utf-8
import re
ret = re.match("[1-9]?\d","")
ret.group()
ret = re.match("[1-9]?\d","")
ret.group()
# 不正确的情况
ret = re.match("[1-9]?\d","")
ret.group()
# 修正之后的
ret = re.match("[1-9]?\d$","")
ret.group()
# 添加|
ret = re.match("[1-9]?\d$|100","")
ret.group()
ret = re.match("[1-9]?\d$|100","")
ret.group()
ret = re.match("[1-9]?\d$|100","")
ret.group()
ret = re.match("[1-9]?\d$|100","")
ret.group()

示例2:( )
需求:匹配出163、126、qq邮箱之间的数字
#coding=utf-8
import re
ret = re.match("\w{4,20}@163\.com", "test@163.com")
ret.group()
ret = re.match("\w{4,20}@(163|126|qq)\.com", "test@126.com")
ret.group()
ret = re.match("\w{4,20}@(163|126|qq)\.com", "test@qq.com")
ret.group()
ret = re.match("\w{4,20}@(163|126|qq)\.com", "test@gmail.com")
ret.group()

python正则表达式(三)的更多相关文章
- Python正则表达式初识(三)
前几天给大家分享了Python正则表达式基础(一)和Python正则表达式基础(二),感兴趣的小伙伴可以点击进去学习,今天继续给大家分享Python正则表达式基础. 1.正则表达式特殊字符“+”,其代 ...
- Python 正则表达式入门(中级篇)
Python 正则表达式入门(中级篇) 初级篇链接:http://www.cnblogs.com/chuxiuhong/p/5885073.html 上一篇我们说在这一篇里,我们会介绍子表达式,向前向 ...
- Python 正则表达式入门(初级篇)
Python 正则表达式入门(初级篇) 本文主要为没有使用正则表达式经验的新手入门所写. 转载请写明出处 引子 首先说 正则表达式是什么? 正则表达式,又称正规表示式.正规表示法.正规表达式.规则表达 ...
- python正则表达式re
Python正则表达式: re 正则表达式的元字符有. ^ $ * ? { [ ] | ( ).表示任意字符[]用来匹配一个指定的字符类别,所谓的字符类别就是你想匹配的一个字符集,对于字符集中的字符可 ...
- Python正则表达式详解
我用双手成就你的梦想 python正则表达式 ^ 匹配开始 $ 匹配行尾 . 匹配出换行符以外的任何单个字符,使用-m选项允许其匹配换行符也是如此 [...] 匹配括号内任何当个字符(也有或的意思) ...
- 比较详细Python正则表达式操作指南(re使用)
比较详细Python正则表达式操作指南(re使用) Python 自1.5版本起增加了re 模块,它提供 Perl 风格的正则表达式模式.Python 1.5之前版本则是通过 regex 模块提供 E ...
- python正则表达式 小例几则
会用到的语法 正则字符 释义 举例 + 前面元素至少出现一次 ab+:ab.abbbb 等 * 前面元素出现0次或多次 ab*:a.ab.abb 等 ? 匹配前面的一次或0次 Ab?: A.Ab 等 ...
- Python天天美味(15) - Python正则表达式操作指南(re使用)(转)
http://www.cnblogs.com/coderzh/archive/2008/05/06/1185755.html 简介 Python 自1.5版本起增加了re 模块,它提供 Perl 风格 ...
- Python正则表达式Regular Expression基本用法
资料来源:http://blog.csdn.net/whycadi/article/details/2011046 直接从网上资料转载过来,作为自己的参考.这个写的很清楚.先拿来看看. 1.正则表 ...
- python 正则表达式汇总
一. 正则表达式基础 1.1.概念介绍 正则表达式是用于处理字符串的强大工具,它并不是Python的一部分. 其他编程语言中也有正则表达式的概念,区别只在于不同的编程语言实现支持的语法数量不同. 它拥 ...
随机推荐
- Command 'ifconfig' not found, but can be installed with: sudo apt install net-tools
然后按照错误信息安安装网络工具: sudo apt install net-tools shl@shl-tx:~$ sudo apt install net-tools正在读取软件包列表... 完成正 ...
- 史上最简单的SpringCloud教程 | 第九篇: 服务链路追踪(Spring Cloud Sleuth)
这篇文章主要讲述服务追踪组件zipkin,Spring Cloud Sleuth集成了zipkin组件. 注意情况: 该案例使用的spring-boot版本1.5.x,没使用2.0.x, 另外本文图3 ...
- Pytorch学习笔记
非线性回归问题的参数求解,反向求导基本流程.Variable 计算时, 它在后台一步步默默地搭建着一个庞大的系统, 叫做计算图, computational graph. 这个图将所有的计算步骤 (节 ...
- .net core支持的操作系统版本
https://github.com/dotnet/core/blob/master/os-lifecycle-policy.md
- 【bzoj4976】宝石镶嵌
题解: 比较水 注意k<=100这个条件 当n-k比较大的时候 我们显然会把它有的位都给取了 不然的话我们可以考虑dp 暴力状压就可以了 代码: #include <bits/stdc++ ...
- 【bzoj1264】[AHOI2006]基因匹配Match 树状数组
题解: 一道比较简单的题目 容易发现状态数只有5*n个 而转移需要满足i1<i2;j1<j2 那么很明显是二维平面数点 暴力一点就是二维树状数组+map 5nlog^3 比较卡常 但是注意 ...
- Python执行ImportError:No module named MySQLdb异常
- python---列表、元祖、字典的区别和常用方法
列表(list) 1.定义: resList=[];----->列表是一种有序的集合 resLIst=[1,2,"嘻嘻",'你好',['内嵌1','内嵌2']]; 2.访问- ...
- BZOJ3675 [Apio2014]序列分割 动态规划 斜率优化
原文链接http://www.cnblogs.com/zhouzhendong/p/8697258.html 题目传送门 - BZOJ3675 题意 对于一个非负整数序列,小H需要重复k次以下的步骤: ...
- docker保存、载入、导出、导入
保存和载入 拿到CONTAINER ID docker ps -a 通过容器id生成镜像dockerlinuxdemoweb:update docker commit b33633d12871 doc ...