I'm New to python and regex. Here I'm trying to recover the text between two limits. The starting could be mov/add/rd/sub/and/etc.. and end limit is end of the line.
/********** sample input text file *************/
f0004030: a0 10 20 02 mov %l0, %psr
//some unwanted lines
f0004034: 90 04 20 03 add %l0, 3, %o0
f0004038: 93 48 00 00 rd %psr, %o1
f000403c: a0 10 3f fe sub %o5, %l0, %g1
/*-------- Here is the code -----------/
try:
objdump = open(dest+name,"r")
except IOError:
print "Error: '" + name + "' not found in " + dest
sys.exit()
objdump_file = objdump.readlines()
for objdump_line in objdump_file:
a = ['add', 'mov','sub','rd', 'and']
if any(x in objdump_line for x in a) # To avoid unwanted lines
>>>>>>>>>> Here is the problem >>>>>>>>>>>>>
m = re.findall ('(add|mov|rd|sub|add)(.*?)($|\n)', objdump_line, re.DOTALL)
<<<<<<<<<<< Here is the problem <<<<<<<<<<<<<
print m
/*---------- Result I'm getting --------------*/
[('mov', ' %l0, %psr', '')]
[('add', ' %l0, 3, %o0', '')]
[('rd', ' %psr, %o1', '')]
[('sub', ' %o5, %l0, %g1', '')]
/*----------- Expected result ----------------*/
[' %l0, %psr']
[' %l0, 3, %o0']
[' %psr, %o1']
[' %o5, %l0, %g1']
I have no Idea why that parentheses and unwanted quotes are coming !!. Thanks in advance.
m = re.findall ('add(.*?)$', objdump_line, re.DOTALL)
It prints out as expected