python正则表达式的学习记录
match和findall的区别以及有括号和无括号的区别
strvar = "hello\n\nworld"
find_re = re.compile("hello[.|\n]*([\S]*)");
rs = find_re.match(strvar); print rs.groups()
#输出('world',) rs = find_re.findall(strvar);
for x in rs:
print x;
#输出world
match是查找到匹配的字符串,也就是括号内的字符串,match应该是从一个字符串里面过滤出我们括号内需要的字符串,所以准确来讲match更像是过滤操作
findall则是从一个字符串里面查找到对应的字符串,直到遇见换行符或者结束符
findall会查找所有匹配的文本,当找到第一个匹配的后,会从第一个匹配的字符串结束位置开始查找
如果上面我们在compile的时候把[.|\n]改成[.],那么正则只会查找到hello\n就停止,这点上感觉有点类似于sed了
python正则表达式的学习记录的更多相关文章
- "利用python进行数据分析"学习记录01
"利用python进行数据分析"学习记录 --day01 08/02 与书相关的资料在 http://github.com/wesm/pydata-book pandas 的2名字 ...
- python核心编程学习记录之正则表达式
- python核心编程学习记录之基础知识
虽然对python的基础知识有所了解,但是为了更深入的学习,要对python的各种经典书籍进行学习 第一章介绍python的优缺点,略过 第二章介绍python起步,第三章介绍python基础,仅记录 ...
- python之爬虫学习记录与心得
之前在寒假的时候,学习了python基础.在慕课网上看的python入门:http://www.imooc.com/learn/177 python进阶:http://www.imooc.com/le ...
- 《灰帽Python-黑客和逆向工程师的Python编程》学习记录
ctypes是Python语言的一个外部库,提供和C语言兼容的数据类型,可以很方便的调用C DLL中的函数. 操作环境:CentOS6.5 Python版本:2.66 ctypes是强大的,强大到本书 ...
- Python有关模块学习记录
1 pandas numpy模块 首先安装搭建好jupyter notebook,运行成功后的截图如下: 安装使用步骤(PS:确定Python安装路径和安装路径里面Scripts文件夹路径已经配置到环 ...
- python matplotlib.pyplot学习记录
matplotlib是python中很强大的绘图工具,在机器学习中经常用到 首先是导入 import matplotlib.pyplot as plt plt中有很多方法,记录下常用的方法 plt.p ...
- python , angular js 学习记录【3】
1.Alembic是SQLAlchemy作者编写的Python数据库迁移工具.用它实现模型类和数据库的同步更新.(安装以及操作步骤 使用Alembic迁移数据库) 使用Alembic添加数据库字段操作 ...
- Python: 利用Python进行数据分析 学习记录
-----15:18 2016/10/14----- 1. import numpy as np;import pandas as pd values = pd.Series(np.random.no ...
随机推荐
- [转载]新功能:用微软的Live Writer离线写博文
原文地址:Writer离线写博文">新功能:用微软的Live Writer离线写博文作者:新浪博客 Writer离线写博文" title="[转载]新功能:用微软的 ...
- css 属性积累
1. letter-spacing:6px; //属性增加或减少字符间的空白(字符间距) 2. cursor // 鼠标移上去的鼠标状态 属性值有: ...
- jq hover方法用法 例子
<script type="text/javascript"> $(function(){ $('.caseslist').hover(functi ...
- jsp页面 date转化成string
1.先引入fmt标签<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%> ...
- 课堂所讲整理:包装&工具类
package org.hanqi.array; import java.util.Random; public class BaoZhuang { public static void main(S ...
- caffe: train error: Serializing 25 layers--- Check failed: proto.SerializeToOstream(&output)
I0221 21:47:41.826748 6797 solver.cpp:259] Train net output #0: loss = 0.00413362 (* 1 = 0.0041 ...
- caffe: compile error: Could not open or find file your path~~/resized_data/0 and a total of 2 images .
I0219 14:48:40.965386 31108 net.cpp:76] Memory required for data: 0I0219 14:48:40.965517 31108 layer ...
- gcviewer待整理
官网:https://github.com/chewiebug/GCViewer G1 Gabage Collector -XX:+UnlockExperimentalVMOptions -XX:+U ...
- 自然语言处理3.3——使用Unicode进行文字处理
全世界有多种语言,经常需要应用程序处理不同的语言和字符集.下面将介绍如何利用Unicode处理使用非ASCII字符集文字. 1.什么是Unicode Unicode支持一百万种以上的字符,每一个字符分 ...
- java-源码下载
jdk7 下载: http://download.java.net/openjdk/jdk7/ jdk8 下载: http://download.java.net/openjdk/jdk8/