免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 4184 | 回复: 0

re.findall---find letters [复制链接]

论坛徽章:
0
发表于 2010-01-24 22:02 |显示全部楼层

               
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
               
               

本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u3/107101/showart_2159279.html
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP