Python 正则表达式

示例:

 1 # -*- coding: gbk -*-
 2 
 3 import re
 4 
 5 def test():
 6     l=re.findall("\|","中国|广东|深圳")
 7     for s in l:
 8         print s
 9     
10     s="中国|广东|深圳"
11     l2=s.split("|")
12     for s in l2:
13         print s
14     
15     pattern=re.compile('[^\d\w\.\;]+')#数字、英文字母、点号、分号之外的字符定义为非法字符
16     if re.match(pattern,'+='):
17         print 'invalid input'
18         
19 if __name__=='__main__':
20     test()

 

正则表达式更多用法,可参考:

http://www.cnblogs.com/huxi/archive/2010/07/04/1771073.html

https://msdn.microsoft.com/zh-cn/library/ae5bf541%28VS.80%29.aspx

posted @ 2016-04-19 19:51  morein2008  阅读(163)  评论(0编辑  收藏  举报