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

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

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

Java代码

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

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

【编辑推荐】

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

2010-03-25 18:25:36

Python正则表达式

2020-11-04 09:23:57

Python

2023-10-07 08:25:09

Java处理工具正则表达式

2018-09-27 15:25:08

正则表达式前端

2010-02-24 17:13:47

2024-09-14 09:18:14

Python正则表达式

2021-01-27 11:34:19

Python正则表达式字符串

2009-02-18 09:48:20

正则表达式Java教程

2016-11-10 16:21:22

Java 正则表达式

2009-09-16 17:29:30

正则表达式使用详解

2012-05-08 13:29:01

VB

2020-09-04 09:16:04

Python正则表达式虚拟机

2024-12-25 15:09:38

Python字符串函数

2010-03-11 08:55:45

python正则表达式

2010-03-01 15:51:59

Python则表达式

2019-12-10 10:40:57

Python正则表达式编程语言

2011-05-11 17:40:30

PHP正则表达式

2011-07-11 12:33:30

JAVA

2009-06-09 09:16:52

Java正则表达式

2009-06-08 16:49:05

Java正则表达式group
点赞
收藏

51CTO技术栈公众号