一般字符和转义字符匹配
图1#!/urs/bin/env python
#!-*-coding:utf-8 -*-
import re
#一般匹配,返回abc
print re.search("abc","abc.163.com").group()
#.匹配非“\n”,返回a%%f
print re.search("a..f","a%%f.163.com.a88f").group()
#\d匹配[0-9],\D非[0-9],返回a fg7kf
print re.search("a\Dfg\dkf","a fg7kf").group()
#\s匹配空字符,\S非空,返回a fg7kf
print re.search("a\Sfg\skf","a?fg kf").group()
#\w匹配字母或数字,\W非字母非数字,返回aGfg kf,a9fg@kf
print re.search("a\wfg\Wkf","aGfg kf").group()
print re.search("a\wfg\Wkf","a9fg@kf").group()
图2
网友评论