This is my code :
import re
a = 'CUSTOMER:SHA\n SERVICE:XX\n MOBILE:12345\n'
match= re.findall(r':[\w]+', a)
print match
The output is : [':SHA', ':XX', ':12345']
I need to eliminate the colon and print the values in newline. How do i do it ?
This is my code :
import re
a = 'CUSTOMER:SHA\n SERVICE:XX\n MOBILE:12345\n'
match= re.findall(r':[\w]+', a)
print match
The output is : [':SHA', ':XX', ':12345']
I need to eliminate the colon and print the values in newline. How do i do it ?
just use this regex
match= re.findall(r':(\w+)', a)
to print on new line you can use for for example:
import re
a = 'CUSTOMER:SHA\n SERVICE:XX\n MOBILE:12345\n'
match= re.findall(r':(\w+)', a)
for i in match:
print(i)
which produce this output:
SHA
XX
12345
You can iterate match to get each value. In each value you can then replace the colon with empty string and print it out. Here is the code you can add to what you already have to accomplish this.
for value in match:
new = value.replace(":", "")
print new
Try this,
import re
a = 'CUSTOMER:SHA\n SERVICE:XX\n MOBILE:12345\n'
for item in re.findall(r':[\w]+', a):
print item[1:]