代码:
1 import re 2 3 text = "JGood is a handsome boy, he is cool, clever, and so on..." 4 print(text) 5 m = re.match(r"(w+)s", text) 6 n = re.search(r"shan(ds)omes", text) 7 if m: 8 print("match: "(w+)s" ") 9 print(m.group(0)) 10 else: 11 print 'not match' 12 13 if n: 14 print("search: "shan(ds)omes"") 15 print(n.group(0)) 16 else: 17 print 'not match'
执行结果:
JGood is a handsome boy, he is cool, clever, and so on... match: "(w+)s" JGood search: "shan(ds)omes" handsome
参考:
http://www.cnblogs.com/sevenyuan/archive/2010/12/06/1898075.html
正则表达式参考:
http://www.runoob.com/regexp/regexp-syntax.html
https://msdn.microsoft.com/zh-cn/library/ae5bf541(v=vs.80).aspx