Created
February 14, 2014 12:19
-
-
Save snowleung/9000098 to your computer and use it in GitHub Desktop.
re module example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#coding:utf8 | |
import re | |
def ex_1(): | |
s = 'aaabcbdbbbccc' | |
pattern = r'(([a-z])\2{2})' | |
pattern = r'([a-z])\1{2}' | |
print 'pattern is :' + pattern | |
print 'string is :' + s | |
return re.findall(pattern, s, re.I) | |
def ex_2(): | |
s = 'aaabcbbbbccc' | |
pattern = r'([a-z])\1{2}' | |
print 'pattern is :' + pattern | |
print 'string is :' + s | |
o = re.match(pattern, s) | |
return o.group() | |
if __name__ == '__main__': | |
print ex_1() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment