To find URLs in a string in Python, we can use regular expressions (regex).
Here is an example code block that shows how to use regex to find URLs in a string:
main.py220 chars8 lines
The output of the code will be a list of all the URLs found in the string:
main.py71 chars2 lines
In the regex pattern, https?:// matches both http:// and https://, [^\s]+ matches any characters that are not whitespace until the end of the URL is reached. The re.findall() function returns all non-overlapping matches of the regex pattern in the input string.
gistlibby LogSnag