Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Jun 17th, 2012  |  syntax: None  |  size: 0.44 KB  |  hits: 17  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Capturing group with findall?
  2. >>> re.findall('abc(de)fg(123)', 'abcdefg123 and again abcdefg123')
  3. [('de', '123'), ('de', '123')]
  4.        
  5. >>> re.findall('(1(23))45', '12345')
  6. [('123', '23')]
  7.        
  8. >>> re.findall('(1(23)45)', '12345')
  9. [('12345', '23')]
  10.        
  11. >>> import re
  12. >>> r = re.compile(r"'(d+)'")
  13. >>> result = r.findall("'1', '2', '345'")
  14. >>> result
  15. ['1', '2', '345']
  16. >>> result[0]
  17. '1'
  18. >>> for item in result:
  19. ...     print(item)
  20. ...
  21. 1
  22. 2
  23. 345
  24. >>>