python 正则例子

好文

http://luy.li/2010/05/12/python-re/  python的正则表达式 re

1 match 返回True false

m = re.match(r'(\d+):(\d+)$', range)

2 findall 返回一个list

doc = re.findall(r'[\x80-\xff]+',line) 匹配用GBK (GB2312/GB18030)编码的所有汉字和标点符号

3 按空格分词。只有中文、中文标点、数字、字母,除此之外的字符都会被作为分隔符忽略,包括标点英文标点。

word=re.findall(r'[a-zA-Z0-9\x80-\xff]+',line)

 http://www.iteye.com/problems/23545   正则表达式replace(/[&'"<>\/\\\-\x00-\x1f\x80-\xff]/g,什么意思?

4.

def wtl(line):
    words=re.findall(r'[0-9:]+',line)
    return words
原文地址:https://www.cnblogs.com/phoenix13suns/p/2973355.html