Python正则表达式怎样进行Java中的使用

开发 后端
Python正则表达式在平时的编写中需要我们不断的学习,下面我们就看看Python正则表达式在Java中的详细使用方案。

Python正则表达式在使用的时候需要注意很多问题,相关的Python正则表达式问题如只有不断的学习才能更好的进行解决。下面我们就看看如何才能更好的学习。希望大家有所收获。

Java代码

  1. #encoding=utf-8   
  2. '''   
  3. python learn regular express   
  4. url : http://docs.python.org/library/re.html   
  5. parse html url : http://www.boddie.org.uk/python/HTML.html   
  6. author : liuzheng   
  7. '''   
  8. import re   
  9. import urllib   
  10. #分析javaeye blog 频道   
  11. class ParseHTML:   
  12. '''   
  13. parse html for infomation   
  14. parse javeeye page   
  15. '''   
  16. def __init__(self,url):   
  17. self.url = url   
  18. pass   
  19. #analyses html   
  20. def parse(self):   
  21. sock = urllib.urlopen(self.url)   
  22. html = sock.read()   
  23. self.__puts(html)   
  24. pass   
  25. #打印html 匹配数据   
  26. def __puts(self,html):   
  27. b = re.compile(r"<a href='([\w./:\\]+?)'[\s]*title=([^<>]+?)
    [\s]*
    target=([^<>]+?)>([^<>]+?)</a>",re.I)   
  28. m = re.findall(b,html)   
  29. #这里有encode 问题?,不知道,大家是否可以帮忙解答   
  30. print m   
  31. if __name__ == '__main__':   
  32. url = "http://www.javaeye.com/blogs"   
  33. p = ParseHTML(url)   
  34. p.parse()   
  35. if __debug__:   
  36. print "debuging is %s" % __debug__   
  37. print "regular" + "* " * 30   
  38. #math   
  39. str = "800-820-8800"   
  40. m = re.match(r"(\d{3})-(\d{3})-(\d{4})", str)   
  41. print "result : " ,m.groups()   
  42. #split   
  43. print "split : %s" % re.split('\W', 'Words, words, words.')   
  44. #findall   
  45. text = "He was carefully disguised but captured quickly 
    by police."
       
  46. print "findall :%s" % re.findall(r"\w+ly",text)   
  47. #sub   
  48. text = "hello world!"   
  49. print "sub:%s" % re.sub(r"\s+","--",text)  

以上就是对Python正则表达式的详细介绍。

【编辑推荐】

  1. Python脚本在游戏中寻找自己的知音
  2. Python语言脚本的安装和配置
  3. Python语言在开发社区中的热议简介
  4. Python 代码安装相关步骤简介
  5. 简介Python代码两大实际应用手册
责任编辑:张浩 来源: IT168
相关推荐

2010-03-25 18:25:36

Python正则表达式

2023-10-07 08:25:09

Java处理工具正则表达式

2020-11-04 09:23:57

Python

2010-02-24 17:13:47

2021-01-27 11:34:19

Python正则表达式字符串

2018-09-27 15:25:08

正则表达式前端

2016-11-10 16:21:22

Java 正则表达式

2009-02-18 09:48:20

正则表达式Java教程

2012-05-08 13:29:01

VB

2009-09-16 17:29:30

正则表达式使用详解

2020-09-04 09:16:04

Python正则表达式虚拟机

2010-03-11 08:55:45

python正则表达式

2019-12-10 10:40:57

Python正则表达式编程语言

2010-03-01 15:51:59

Python则表达式

2009-06-08 16:49:05

Java正则表达式group

2011-05-11 17:40:30

PHP正则表达式

2011-07-11 12:33:30

JAVA

2009-06-09 09:16:52

Java正则表达式

2010-07-14 09:47:04

Perl正则表达式

2010-07-28 11:12:19

Flex正则表达式
点赞
收藏

51CTO技术栈公众号