[ create a new paste ] login | about

Link: http://codepad.org/2RO2iS4O    [ raw code | output | fork ]

Python, pasted on Aug 22:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
import sys, os
print sys.version
print [os.uname()[i] for i in [0, 2, 3, 4]]

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"
print re.sub(pattern, replace, text, re.MULTILINE) + "\n\n"
print re.sub(pattern, replace, text) + "\n\n"
#print re.subn(pattern, replace, text, 0, re.MULTILINE)[0] + "\n\n" # Only has 4 args in Python 2.5?
regex = re.compile(pattern, re.MULTILINE)
print regex.sub(replace, text)


Output:
2.5.1 (r251:54863, May  4 2007, 16:52:23) 
[GCC 4.1.2]
['Linux', '2.6.22-rc5', '#2 Mon Jul 2 10:14:22 GMT 2007', 'i686']
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;


	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;


	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,


	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,


Create a new paste based on this one


Comments: