- 论坛徽章:
- 0
|
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 |
|