正则表达式 re.findall 用法
正则 re.findall 的简单用法(返回string中所有与pattern相匹配的全部字串,返回形式为数组)
语法:
findall(pattern, string, flags=0)
import re
Python 正则表达式 re findall 方法能够以列表的形式返回能匹配的子串
print (help(re.findall))
print (dir(re.findall))
findall查找全部r标识代表后面是正则的语句
regular_v1 = re.findall(r"docs",“https://docs.python.org/3/whatsnew/3.6.html”)
print (regular_v1)
[‘docs’]
符号^表示匹配以https开头的的字符串返回,
regular_v2 = re.findall(r"^https","https://docs.python.org/3/whatsnew/3.6.html")print (regular_v2)['https']
用$符号表示以html结尾的字符串返回,判断是否字符串结束的字符串
regular_v3 = re.findall(r"html$","https://docs.python.org/3/whatsnew/3.6.html")
print (regular_v3)
['html']
[…]匹配括号中的其中一个字符
regular_v4 = re.findall(r"[t,w]h","https://docs.python.org/3/whatsnew/3.6.html")
print (regular_v4)['th', 'wh']
“d”是正则语法规则用来匹配0到9之间的数返回列表
regular_v5 = re.findall(r"\d","https://docs.python.org/3/whatsnew/3.6.html")
regular_v6 = re.findall(r"\d\d\d","https://docs.python.org/3/whatsnew/3.6.html/1234")
print (regular_v5)
['3', '3', '6']
print (regular_v6)
['123']
小d表示取数字0-9,大D表示不要数字,也就是出了数字以外的内容返回
regular_v7 = re.findall(r"\D",“https://docs.python.org/3/whatsnew/3.6.html”)
print (regular_v7)
[‘h’, ‘t’, ‘t’, ‘p’, ‘s’, ‘:’, ‘/’, ‘/’, ‘d’, ‘o’, ‘c’, ‘s’, ‘.’, ‘p’, ‘y’, ‘t’, ‘h’, ‘o’, ‘n’, ‘.’, ‘o’, ‘r’, ‘g’, ‘/’, ‘/’, ‘w’, ‘h’, ‘a’, ‘t’, ‘s’, ‘n’, ‘e’, ‘w’, ‘/’, ‘.’, ‘.’, ‘h’, ‘t’, ‘m’, ‘l’]
“w”在正则里面代表匹配从小写a到z,大写A到Z,数字0到9
regular_v8 = re.findall(r"\w","https://docs.python.org/3/whatsnew/3.6.html")
print (regular_v8)
['h', 't', 't', 'p', 's', 'd', 'o', 'c', 's', 'p', 'y', 't', 'h', 'o', 'n', 'o', 'r', 'g', '3', 'w', 'h', 'a', 't', 's', 'n', 'e', 'w', '3', '6', 'h', 't', 'm', 'l']
“W”在正则里面代表匹配除了字母与数字以外的特殊符号
regular_v9 = re.findall(r"\W","https://docs.python.org/3/whatsnew/3.6.html")
print (regular_v9)
[':', '/', '/', '.', '.', '/', '/', '/', '.', '.']
正则表达式 re.findall 用法相关推荐
- 正则表达式 re.findall 用法,包含正则规则讲解
正则表达式 re.findall 用法 正则 re.findall 的简单用法(返回string中所有与pattern相匹配的全部字串,返回形式为数组) 语法: 1 findall(pattern, ...
- python正则findall函数的用法_python中正则表达式 re.findall 用法
python中正则表达式 re.findall 用法 Python 正则表达式 正则表达式是一个特殊的字符序列,它能帮助你方便的检查一个字符串是否与某种模式匹配. Python 自1.5版本起增加了r ...
- python正则表达式findall_正则表达式 re.findall 用法
正则 re.findall 的简单用法(返回string中所有与pattern相匹配的全部字串,返回形式为数组) 语法: findall(pattern, string, flags=0) impor ...
- Python中正则表达式findall用法
一:前言 在写着自动化测试的脚本时,重新复习了一下正则表达式findall()方法.为了深化印象,输出点东西,就来写个通过正则表达式爬取菜鸟教程标题的小案例. 参考教程:菜鸟教程之Python正则表达 ...
- Python 内置模块之 re 库,一文搞定正则表达式初阶用法,滚雪球学 Python 第 13 篇
橡皮擦,一个逗趣的互联网高级网虫.新的系列,让我们一起 Be More Pythonic. 滚雪球学 Python 第二轮 已完成的文章清单 十三.Python 内置模块之 re 库,一文搞定正则表达 ...
- python正则表达式re.sub用法
python正则表达式re.sub用法 https://cloud.tencent.com/developer/article/1382055 python正则表达式re.sub用法 全面的 http ...
- python 正则表达式 re findall 返回能匹配的字符串
python 正则表达式 re findall 方法能够以列表的形式返回能匹配的子串. re.findall(pattern, string[, flags]): 搜索string,以列表形式返回全部 ...
- php正则表达式函数案例,PHP正则表达式函数preg_replace用法实例分析
PHP正则表达式函数preg_replace用法.,具体如下: preg_replace 执行一个正则表达式的搜索和替换 语法:preg_replace (pattern ,replacement , ...
- oracle中取反_oracle正则表达式regexp_like的用法详解
oracle正则表达式regexp_like的用法详解 更新时间:2013年06月13日 17:42:05 作者: 本篇文章是对oracle正则表达式regexp_like的用法进行了详细的分析介 ...
最新文章
- 26岁已经是“双一流”高校博导!读博期间也曾两次想要退学......
- 近期学习oracle 数据库总结
- paip.http 404错误 的解决
- Python----Day1
- android 云应用开发,Android云应用开发:网络通信技术介绍
- 【svn】svn的使用
- ping命令整个过程详解
- SharePoint 编程指南(转)
- seo全攻略_SaaS 企业推广获客全攻略(2):如何做好企业官网?
- 3个可以写进简历的京东AI NLP项目实战
- sap 导出系统所有的单位_导出SAP系统表结构及数据供HANA使用
- sklearn——决策树基础概念
- cocos2d-xFinalProject踩坑记录(cocosStudio控件获取,角色移动及动画,碰撞检测,背景音乐与场景)...
- 未处理的异常: 0xC0000005: 读取位置 0x00000000 时发生访问冲突
- SUSE12 sp1如何进入单用户模式
- 阿里达摩院做AI这两年
- SQL Server 2008 远程过程调用失败的问题解决方法
- 双十一大促淘宝主图设置优化方法
- 网页分享功能 支持 微信二维码 qq空间 qq好友 新浪微博 百度贴吧 豆瓣 人人...
- java-01背包(动态规划)