Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # basic_image_regex_demo.py
- imgReg = '''["'](?i)(\S+\.jpe?g)$'''
- print 'Basic Image Regex Demo --'
- print
- print '***',imgReg,'***'
- print
- import re
- def okay(test):
- print test[2:],'=',
- print re.findall(imgReg,test)
- okay('''="test.jpg''')
- okay('''="TEST.jpg''')
- okay('''="2.jpg''')
- okay('''='test.jpg''')
- okay('''="test.jpeg''')
- okay('''="test.JPG''')
- okay('''="test.JPEG''')
- okay('''="jpg''')
- okay('''=".jpg''')
- okay('''="test.gif''') # <<< '''["'](?i)(\S+\.(jpe?g|gif))$''' gave [('test.gif', 'gif')] ???
- okay('''="test.jpgx''')
- okay('''x="test.jpg''')
- print "\nSolution to add other common image extensions --"
- print
- imgReg2 = '''["'](?i)(\S+\.(?:jpe?g|gif|bmp))$'''
- print '***',imgReg2,'***'
- print
- def okay(test):
- print test[2:], '=',
- print re.findall(imgReg2, test)
- okay('''="test.jpg''')
- okay('''="TEST.gif''')
- okay('''="2.jpg''')
- okay('''='test.bmp''')
- okay('''="test.jpeg''')
- okay('''="test.JPG''')
- okay('''="test.JPEG''')
- okay('''="jpg''')
- okay('''=".jpg''')
- okay('''="test.gif''')
- okay('''="test.jpgx''')
- okay('''x="test.jpg''')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement