python使用正则表达式匹配字符串开头并打印示例
作者:ORACLE800 时间:2021-07-02 00:52:13
本文实例讲述了python使用正则表达式匹配字符串开头并打印的方法。分享给大家供大家参考,具体如下:
import re
s="name=z1hangshan username=fff url=www.baidu.com password=ddd256"
s2="username=fff name=z1hangshan url=www.baidu.com password=ddd256"
#p=re.compile(r'((?:\s)name=(\S)+)')
p=re.compile(r'(^name=(\S)+)')
iter=p.finditer(s)
for m in iter:
print "m", m.group()
iter2=p.finditer(s2)
for m2 in iter:
print "m2", m2.group()
#m username=fff
#m2 不匹配
PS:这里再为大家提供2款非常方便的正则表达式工具供大家参考使用:
JavaScript正则表达式在线测试工具:
http://tools.jb51.net/regex/javascript
正则表达式在线生成工具:
http://tools.jb51.net/regex/create_reg
希望本文所述对大家Python程序设计有所帮助。
标签:python,正则表达式,匹配,字符串
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
php+mysqli实现批量替换数据库表前缀的方法
2023-11-22 10:15:55
![](https://img.aspxhome.com/file/2023/2/94722_0s.jpg)
uniapp路由uni-simple-router实例详解
2023-09-24 21:27:04
Python实现自动驾驶训练模型
2023-07-28 18:45:29
![](https://img.aspxhome.com/file/2023/1/61481_0s.png)
Python开发之迭代器&生成器的实战案例分享
2021-03-18 17:34:33
python爬虫看看虎牙女主播中谁最“顶”步骤详解
2022-03-31 09:30:33
![](https://img.aspxhome.com/file/2023/2/84152_0s.png)
Python实现拷贝多个文件到同一目录的方法
2021-09-03 20:56:25
ASP中取得图片宽度和高度的类
2008-10-29 12:38:00
ubuntu 18.04 安装opencv3.4.5的教程(图解)
2022-10-29 16:36:01
![](https://img.aspxhome.com/file/2023/6/90566_0s.jpg)
Python实现App自动签到领取积分功能
2021-09-16 15:59:59
![](https://img.aspxhome.com/file/2023/1/95571_0s.jpg)
在ASP中使用Oracle数据库技巧
2008-05-17 11:47:00
mysql 插入优化
2010-12-14 15:29:00
ASP+SQL Server构建网页防火墙
2009-01-21 19:56:00
PHP登录验证功能示例【用户名、密码、验证码、数据库、已登陆验证、自动登录和注销登录等】
2023-11-14 23:24:02
![](https://img.aspxhome.com/file/2023/5/86925_0s.png)
python装饰器代码解析
2021-12-29 19:39:07
python判断自身是否正在运行的方法
2022-07-30 02:34:44
python如何求解两数的最大公约数
2021-01-16 07:38:18
从一个项目中来看三层架构
2008-08-06 12:50:00
网页设计求职全攻略
2008-07-09 18:56:00
python练习程序批量修改文件名
2022-01-29 06:53:12
opencv实现车牌识别
2023-08-10 01:59:38