The replace_urls() method in Python replaces all the URLs in a given text with the replacement string.
clean-text?clean-text is a third-party package that pre-processes text data to obtain a normalized text representation.
The package can be installed using the pip command. We can check the following command to install the clean-text package.
pip install clean-text
replace_urls(text, replace_with="<URL>")
text: This is the text data.replace_with: This is the replacement string.The method returns the text data where the URLs are replaced by the replacement string.
import cleantextstring = """hello educative - https://educative.io - hello edpresso"""new_string = cleantext.replace_urls(string, replace_with="EDU_URL")print("Original String - '" + string + "'")print("Modified String - '" + new_string + "'")
cleantext package.EDU_URL using the replace_urls() method.