Skip to content

Instantly share code, notes, and snippets.

@jonspeicher
Created April 22, 2010 15:17
Show Gist options
  • Save jonspeicher/375361 to your computer and use it in GitHub Desktop.
Save jonspeicher/375361 to your computer and use it in GitHub Desktop.
Recursively perform multiline regex substitution in files matching a spec.
#!/usr/bin/env python
import re, os
SEARCH_PATTERN = '^(\s*)\/>\s*<Platform\s*Name=\"WexEVM \(ARMV4I\)\"\s*\/>\s*$'
REPLACE_PATTERN = r'\1/>'
pattern = re.compile(SEARCH_PATTERN, re.MULTILINE)
for (dirpath, dirnames, filenames) in os.walk('.'):
for filename in filenames:
if re.search('\.vcproj$', filename):
fullname = dirpath + '/' + filename
text = re.sub(pattern, REPLACE_PATTERN, file(fullname).read())
file(fullname, 'w').write(text)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment