Advertisement
here2share

# basic_image_regex_demo.py ^ 2019.04

Jul 26th, 2015
373
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # basic_image_regex_demo.py
  2.  
  3. imgReg = '''["'](?i)(\S+\.jpe?g)$'''
  4.  
  5. print 'Basic Image Regex Demo --'
  6. print
  7. print '***',imgReg,'***'
  8. print
  9.  
  10. import re
  11. def okay(test):
  12.     print test[2:],'=',
  13.     print re.findall(imgReg,test)
  14. okay('''="test.jpg''')
  15. okay('''="TEST.jpg''')
  16. okay('''="2.jpg''')
  17. okay('''='test.jpg''')
  18. okay('''="test.jpeg''')
  19. okay('''="test.JPG''')
  20. okay('''="test.JPEG''')
  21. okay('''="jpg''')
  22. okay('''=".jpg''')
  23. okay('''="test.gif''') # <<< '''["'](?i)(\S+\.(jpe?g|gif))$''' gave [('test.gif', 'gif')] ???
  24. okay('''="test.jpgx''')
  25. okay('''x="test.jpg''')
  26.  
  27. print "\nSolution to add other common image extensions --"
  28. print
  29.  
  30. imgReg2 = '''["'](?i)(\S+\.(?:jpe?g|gif|bmp))$'''
  31. print '***',imgReg2,'***'
  32. print
  33.  
  34. def okay(test):
  35.     print test[2:], '=',
  36.     print re.findall(imgReg2, test)
  37. okay('''="test.jpg''')
  38. okay('''="TEST.gif''')
  39. okay('''="2.jpg''')
  40. okay('''='test.bmp''')
  41. okay('''="test.jpeg''')
  42. okay('''="test.JPG''')
  43. okay('''="test.JPEG''')
  44. okay('''="jpg''')
  45. okay('''=".jpg''')
  46. okay('''="test.gif''')
  47. okay('''="test.jpgx''')
  48. okay('''x="test.jpg''')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement