python 正则表达式中怎么提取并修改已匹配到的字符串?
1个回答
展开全部
# -*- coding: utf-8 -*-
__author__ = 'lpe234'
__date__ = '2014-11-16'
text = """
I had no real home, no money, no job, and no friends that cared.
Not one person had even sent me a sympathy card for my loss.
"""
def main():
global text
text_list = text.split()
for index, word in enumerate(text_list):
word = word.lower()
if word.startswith('a'):
text_list[index] = word+'hey'
text = ' '.join(text_list)
print text
if __name__ == '__main__':
main()
and the results:
C:\Python27\python.exe D:/ofshion_min_spider/scrapper/djangoo/find_a.py
I had no real home, no money, no job, andhey no friends that cared. Not one person had even sent me ahey sympathy card for my loss.
Process finished with exit code 0
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询