是个传颂厨

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::
# -*-coding:utf-8 -*-
import re

scerct_code = 'qwxxlxxerxxoxxtyxxvxxuixxexxop'
scerct_code_0 = 'qwxxlxxerxx' \
                'oxxtyxxvxxuixxexxop'
a = re.findall('q.',scerct_code)#.占位符,匹配任意字符除了换行符/n
b = re.findall('q*',scerct_code)#*匹配前一个字符0or无穷次
c = re.findall('q?',scerct_code)#?匹配前一个字符0or1次
#findall匹配所有并返回
#Search匹配第一个,用group()参数表示第几个
#Sub替换符合,返回替换值

print re.findall('xx.*xx',scerct_code)
print re.findall('xx.*?xx',scerct_code)
print re.findall('xx(.*?)xx',scerct_code)
print re.findall('xx(.*?)xx',scerct_code_0,re.S)#re.S粗略理解为换行匹配

 

posted on 2016-05-13 20:30  是个传颂厨  阅读(121)  评论(0编辑  收藏  举报