#!/usr/bin/env python
import re
r = "aasa da.5a5dfgfda ada"
ret = re.findall('a',r)
print(ret)#1.查找全部a
ret = re.findall('^a',r)
print(ret)# 2.^ 查找开头
ret = re.findall('a$',r)
print(ret)#3. $ 查找结尾
ret = re.findall('a*',r)
print(ret)#4. * 贪婪匹配0到多次
ret = re.findall('a+',r)
print(ret)#5. + 贪婪匹配1到多次
ret = re.findall('a?',r)
print(ret)#6. ? 贪婪匹配0到1次
ret = re.findall('a{2}',r)
print(ret)#7. {} 贪婪匹配指定次数
ret = re.findall('a{1,2}',r)
print(ret)#8. {m ,n} 贪婪匹配指定区间次数
ret = re.findall('a[ad]',r)
print(ret)#9. [] 【ad】a或d
ret = re.findall('a.',r)
print(ret)#10. . 匹配除换行符以外的任意字符
ret = re.findall('a[.]',r)
print(ret)#11. [.] 元字符在字符集中无效
ret = re.findall('a\w',r)
print(ret)#12. \w 匹配字母或数字或下划线或汉字
ret = re.findall('a\s',r)
print(ret)#13. \s 匹配任意的空白符
ret = re.findall('a\d',r)
print(ret)#14. \d 匹配数字
ret = re.findall(r'a\b',r)
print(ret)#15. \b 匹配单词的开始或结束
结果:
 ['a', 'a', 'a', 'a', 'a', 'a', 'a', 'a']
['a']
['a']
['aa', '', 'a', '', '', 'a', '', '', 'a', '', '', '', '', '', '', 'a', '', 'a', '', 'a', '']
['aa', 'a', 'a', 'a', 'a', 'a', 'a']
['a', 'a', '', 'a', '', '', 'a', '', '', 'a', '', '', '', '', '', '', 'a', '', 'a', '', 'a', '']
['aa']
['aa', 'a', 'a', 'a', 'a', 'a', 'a']
['aa', 'ad']
['aa', 'a ', 'a.', 'a5', 'a ', 'ad']
['a.']
['aa', 'a5', 'ad']
['a ', 'a ']
['a5']
['a', 'a', 'a', 'a']

 

随机推荐

  1. dom 兼容性问题1_节点部分

    AS : ECMAScript xml . html js组成: 1,ECMAScript : 是Javascript的核心标准.同时也是一个解释器. 2,DOM: document object m ...

  2. php/oracle: 解析oracle表中的NCLOB,CLOB字段里面的内容

    php/oracle: 解析oracle表中的NCLOB,CLOB字段里面的内容 假如你的字段名是:passenger_info 字段类型是:NCLOB/CLOB,在读表的时候,需要将 passeng ...

  3. 2016-02-20WebForm登陆验证,判断用户是否登陆 PageBase类

    http://blog.csdn.net/fanbin168/article/details/49404233 很多时候,WebFrom页面,我们需要判断用户是否已经登陆了.假如有很多页面,难道我们要 ...

  4. Ceph pg分裂流程及可行性分析

    转自:https://www.ustack.com/blog/ceph-pg-fenlie/ 1 pg分裂 Ceph作为一个scalable的分布式系统,集群规模会逐渐增大,为了保证数据分布的均匀性, ...

  5. 一些蠕虫传播研究的文章——TODO

    www.arocmag.com/getarticle/?aid=4e02d91c19b0cced Internet 蠕虫防范技术研究http://www.arocmag.com/article/100 ...

  6. MAMP mac下启动Mysql

    MAMP mac下启动Mysql /Applications/MAMP/Library/bin/mysql -u root -p 初始密码 root:

  7. Leetcode 509. Fibonacci Number

    class Solution(object): def fib(self, N): """ :type N: int :rtype: int ""&q ...

  8. CANopenSocket CANopenCommand.c hacking

    /***************************************************************************** * CANopenSocket CANop ...

  9. [BZOJ5249][多省联测2018]IIIDX

    bzoj luogu sol 首先可以把依赖关系转成一个森林.自下而上维护出每个点的\(size\),表示这关解锁以后一共有多少关. 考虑没有重复数字的情况. 直接从小往大贪心把每个数赋给当前已解锁的 ...

  10. LeetCode LFU Cache

    原题链接在这里:https://leetcode.com/problems/lfu-cache/?tab=Description 题目: Design and implement a data str ...