Chinaunix首页 | 论坛 | 博客
  • 博客访问: 265520
  • 博文数量: 113
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 1044
  • 用 户 组: 普通用户
  • 注册时间: 2015-02-15 16:09
文章分类

全部博文(113)

文章存档

2016年(5)

2015年(108)

我的朋友

分类: Python/Ruby

2015-10-07 17:37:48


点击(此处)折叠或打开

  1. #fengzhaung
  2. import re
  3. r1=r"\d{3,4}-?\d{8}"
  4. print re.findall(r1,'010-87654321')
  5. #equal
  6. #编译后正则,运行更快
  7. p_tel=re.compile(r1)
  8. print p_tel.findall('010-87654321')
  9. #也可以接受特殊标志,不区分大小写
  10. spell_re=re.compile(r'csvt',re.I)
  11. print spell_re.findall('CSVT')
  12. #执行匹配match() starting
  13. # search() anywhere
  14. spell_re.match('csvt hello ')
  15. x=spell_re.match('csvt hello')
  16. print x.group(0)
  17. #
  18. spell_re.search('hello csvt')
  19. # findall()
  20. spell_re.findall('hello csvt hello csvt csvt')
  21. #finditer()
  22. x=spell_re.finditer('hello csvt hello csvt csvt')
  23. ###match de
  24. #group() 返回被RE 匹配的字符串
  25. #start() 匹配开始位置
  26. #end()    匹配结束位置
  27. #span()


  28. ######
  29. ###模块级函数
  30. #replace
  31. s="hello csvt"
  32. s.replace('csvt','python')
  33. ###replace
  34. rs=r'c..t'
  35. print re.sub(rs,'python','csvt caat cvvt cccc')
  36. print re.subn(rs,'python','csvt caat cvvt cccc')
  37. ####
  38. s='123+456-789*000'
  39. re.split(r'[\+\-\*]',s)

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