Advertisement
Guest User

Untitled

a guest
May 22nd, 2015
194
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.58 KB | None | 0 0
  1. #!/usr/bin/env python
  2. #
  3. # Copyright 2007 Doug Hellmann.
  4. #
  5. """Searching memory mapped files with regular expressions.
  6. """
  7.  
  8. __version__ = "$Id$"
  9. #end_pymotw_header
  10.  
  11. import mmap
  12. import re
  13. import contextlib
  14.  
  15. pattern = re.compile(r'(\.\W+)?([^.]?nulla[^.]*?\.)',
  16. re.DOTALL | re.IGNORECASE | re.MULTILINE)
  17.  
  18. with open('lorem.txt', 'r') as f:
  19. with contextlib.closing(mmap.mmap(f.fileno(), 0,
  20. access=mmap.ACCESS_READ)
  21. ) as m:
  22. for match in pattern.findall(m):
  23. print match[1].replace('\n', ' ')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement