Chinaunix首页 | 论坛 | 博客
  • 博客访问: 112568
  • 博文数量: 49
  • 博客积分: 2612
  • 博客等级: 少校
  • 技术积分: 431
  • 用 户 组: 普通用户
  • 注册时间: 2009-12-01 14:31
个人简介

来来去去

文章分类

全部博文(49)

文章存档

2015年(1)

2012年(4)

2011年(1)

2010年(42)

2009年(1)

我的朋友

分类: Python/Ruby

2010-01-24 22:02:44

re.findall(pattern, string[, flags])

Return all non-overlapping matches of pattern in string, as a list of strings. The string is scanned left-to-right, and matches are returned in the order found. If one or more groups are present in the pattern, return a list of groups; this will be a list of tuples if the pattern has more than one group. Empty matches are included in the result unless they touch the beginning of another match.

     findall 匹配串中所有符合条件的串,并以LIST的形式返回。
以下这个程序用来匹配前后(只)有三个大写字母的小写字母。如“sEFCgETYt”中的g.

'''This program use for select the lowcharacter which have three capital letters before and after
the the lower case letters, such as '
ABCdEFG'.'''
import os
import sys
import re

if __name__=='__main__':
    f=open("E:\pythonchallenge\letters\letters.txt","r")
    src=f.read()
    m=''.join(re.findall('[^A-Z][A-Z]{3}([a-z])[A-Z]{3}[^A-Z]',src))
    print m


阅读(711) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~