https://docs.python.org/2/library/re.html##!/usr/bin/python #-*-coding:utf8-*- """ @author: yugengde @contact: yugengde@163.com @file : re.py @time: 2017/8/7 21:25 """ import re # 1. pattern = re.compile(r'hello') match = pattern.match("helloworld") if match: print match.group() pattern.findall("str") pattern.split("str") # 用匹配的字符串进行分割 # # # 2. # match = re.match(r"hello","helloworld") # print match # if match: # print match.group() p = re.compile(r"\d") # \d 数字 \D 非数字 \s 空白字符 \S 非空白字符 \w [a-zA-Z0-9_] \W re.sub(r"[abc]",'o',"str") res = p.findall("hell348dhefh7483") print res print ''.join(res) if __name__ == '__main__': pass