Iam writing a program to find and replace a string from all the files with the given extension.
Here Iam using regular expressions for searching.The task is to findall the occurances and modify those.
If my string is "The number is 1234567890"
Result after searching and replacing should be +911234567890
I think i can re.sub() here like
s = "The number is 1234567890"
re.sub(r"\d{10}",??,s)
What can be given as the second argument here i don't know what the number would be i have modify the same matched string by preceding it with +91
I could do it using the findall from re and replace from string like
s = "The number is 1234567890 and 2345678901"
matches = re.findall(r'\d{10}',s)
for match in matches:
s = s.replace(match,"+91"+match)
After this s is The number is +911234567890 and +912345678901
Is this the only way of doing it??Is it not possible using re.sub() ?? If it is please help me.Thank you...!