Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Regex add character before word

import re
text = 'https://app.propertymeld.com/1568/v/23256/meld/4376491/'
d = re.sub(r'(meld)', r'\1s', text)
e = re.sub(r'api',r'(/meld)', d)
print(e)

required solution : "https://app.propertymeld.com/1568/v/23256/api/melds/4376491/tenant-files/"

Is there any solution to add the word api before the word melds.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Try:

import re

text = 'https://app.propertymeld.com/1568/v/23256/meld/4376491/'

e = re.sub(r'/meld', '/api/melds', text)

print(e)

OUTPUT:

https://app.propertymeld.com/1568/v/23256/api/melds/4376491/

Note:

If you want tenant-files/ at the end, then

e = re.sub(r'/meld', '/api/melds', text) + "tenant-files/"

output:

https://app.propertymeld.com/1568/v/23256/api/melds/4376491/tenant-files/
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading