DAY5 python练习

“”"
请用正则表达式,找出下面字符串中所有c开头的单词,
结果是一个列表,列表里面每一个元素是一个单词’
“”"
import re
s =
“”"
And now, the end is near  And so I face the final curtain  My friend, I’ll make it clear
I’ll state my case, of which I’m certain
“”"

res = re.compile(r"\b c\w+")
result = re.findall(res,s)
print(result)

s=
“”“se234 1987-02-09 07:30:00
1987-02-10 07:25:00
“””

res = re.compile(r"\d{4}-\d{2}-\d{2}\s*\d{2}:\d{2}:\d{2}")
result = re.findall(res,s)
print(result)

‘用正则表达式筛选出,只包含字母、空格和数字的行,结果是一个列表,每个元素是一行’
s=
“”"
i love you not because
12sd 34er*% 56
df e4*%$ 5@%!4434
sfi hi q94 729
**
“”"

res=re.compile(r"\n ([ \w]+)\n")
result=re.split(res,s)
print(result)

s = ‘’’
And now, the end is near;
  现在,我的末日将近,
  And so I face the final curtain.
  面临人生的最后落幕,
  My friend, I’ll make it clear,
  我的朋友,我要说个清楚,
  I’ll state my case, of which I’m certain.
  向你讲述我的人生之路。
  I’ve lived a life that’s full.
  我活过一个充实的人生,
  I’ve traveled each and every highway;
  我经历过每一段路途,
  And more, much more I did,
  而更重要的是,
  I did it my way.
  我用自己的方式。
  Regrets, I’ve had a few;
  遗憾,也有一些吧,
  But then again, too few to mention.
  算不上多,不值一提。
  I did what I had to do
  我做了该做的一切,
  And saw it through without exemption.
  洞悉世事,不求赦免。
  I planned each charted course;
  我规划过每一段人生,
  Each careful step along the by way,
  每一个细微的脚步,
  and more, much more than this,
  而更重要的是,
  I did it my way.
  我用自己的方式。
  Yes, there were times, I’m sure you knew
  是的,你知道有些时候,
  When I bit off more than I could chew.
  我曾背负不能承受之重,
  But through it all, when there was doubt,
  但自始至终,就算充满疑惑,
  I ate it up and spit it out.
  我还是克服困难战胜了它。
  I faced it all and I stood tall;
  我挺直身躯,勇敢面对,
  And did it my way.
  用我自己的方式。
  I’ve loved, I’ve laughed and cried.
  我曾经爱过,笑过,哭过,
  I’ve had my fill; my share of losing.
  我曾经满足,也曾经失落,
  And now, as tears subside,
  现在,当泪水慢慢沉淀,
  I find it all so amusing.
  我发现原来可以一笑置之。
  To think I did all that;
  想到我所做过的一切,
  And may I say - not in a shy way,
  我可以说,毫不羞愧地说,
  No, oh no not me,
  我没有虚度,
  I did it my way.
  我用自己的方式。
  For what is a man, what has he got?
  男人究竟是什么,拥有什么?
  If not himself, then he has naught.
  除了自己,我们一无所有。
  To say the things he truly feels;
  说出心里最真实的感受,
  And not the words of one who kneels.
  而不是那些身不由己的话。
  The record shows I took the blows -
  时间证明,我经受住了磨难,
  And did it my way!
  用我自己的方式!
  Yes, it was my way.
  没错,这就是我的方式。
‘’’

L1=[]
res=re.compile(r"\n(\s+[a-zA-Z \.]+)\n")
result=re.findall(res,s)

for i in result:
    print(i)
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值