Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- >> import sys, os
- >>> print sys.version
- 2.7.3 (default, Aug 1 2012, 05:14:39)
- [GCC 4.6.3]
- >>> print [os.uname()[i] for i in [0, 2, 3, 4]]
- ['Linux', '3.2.0-25-generic', '#40-Ubuntu SMP Wed May 23 20:30:51 UTC 2012', 'x86_64']
- >>> import re
- >>> pattern = r'int (\w+) = (.*?);'
- >>> replace = r'\t\1 = \2,'
- >>> text = 'int x = 5;\nint x = 5;\nint x = 5;\nint x = 5;\nint y = 5;\nint x = 5;\nint x = 5;\nint x = 5;\nint x = 5;\nint x = 5;\nint x = 5;\nint x = 5;\nint x = 5;\nint x = 5;\nint x = 5;\nint x = 5;\nint x = 5;'
- >>> print text, "\n\n"
- int x = 5;
- int x = 5;
- int x = 5;
- int x = 5;
- int y = 5;
- int x = 5;
- int x = 5;
- int x = 5;
- int x = 5;
- int x = 5;
- int x = 5;
- int x = 5;
- int x = 5;
- int x = 5;
- int x = 5;
- int x = 5;
- int x = 5;
- >>> print re.sub(pattern, replace, text, re.MULTILINE), "\n\n"
- x = 5,
- x = 5,
- x = 5,
- x = 5,
- y = 5,
- x = 5,
- x = 5,
- x = 5,
- int x = 5;
- int x = 5;
- int x = 5;
- int x = 5;
- int x = 5;
- int x = 5;
- int x = 5;
- int x = 5;
- int x = 5;
- >>> print re.sub(pattern, replace, text), "\n\n"
- x = 5,
- x = 5,
- x = 5,
- x = 5,
- y = 5,
- x = 5,
- x = 5,
- x = 5,
- x = 5,
- x = 5,
- x = 5,
- x = 5,
- x = 5,
- x = 5,
- x = 5,
- x = 5,
- x = 5,
- >>> print re.subn(pattern, replace, text, 0, re.MULTILINE)[0], "\n\n"
- x = 5,
- x = 5,
- x = 5,
- x = 5,
- y = 5,
- x = 5,
- x = 5,
- x = 5,
- x = 5,
- x = 5,
- x = 5,
- x = 5,
- x = 5,
- x = 5,
- x = 5,
- x = 5,
- x = 5,
- >>> regex = re.compile(pattern, re.MULTILINE)
- >>> print regex.sub(replace, text)
- x = 5,
- x = 5,
- x = 5,
- x = 5,
- y = 5,
- x = 5,
- x = 5,
- x = 5,
- x = 5,
- x = 5,
- x = 5,
- x = 5,
- x = 5,
- x = 5,
- x = 5,
- x = 5,
- x = 5,
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement