I need to replace ‘AUTO’ with ‘ALL’. Can anyone help with a regex to do that?
‘https://eur-lex.europa.eu/legal-content/AUTO/?uri=CELEX:52022DC0085’
needs to become the below string:
‘https://eur-lex.europa.eu/legal-content/ALL/?uri=CELEX:52022DC0085’
>Solution :
You don’t necessarily need to use regex in this case. Here are some ideas that should get you your desired result:
Using string replace method:
u=url.replace('AUTO', 'ALL')
Using re module with string method:
import re
u=url.replace(re.search(r'AUTO', url)[0], 'ALL')