Skip to content

Instantly share code, notes, and snippets.

@snowleung
Created February 14, 2014 12:19
Show Gist options
  • Save snowleung/9000098 to your computer and use it in GitHub Desktop.
Save snowleung/9000098 to your computer and use it in GitHub Desktop.
re module example
#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