URL Extraction Function

  • Share this:

Code introduction


Extracts all URLs from the given text.


Technology Stack : Regular expressions (re)

Code Type : Function

Code Difficulty : Intermediate


                
                    
import re
import math
import random
import datetime
import hashlib
import sys

def extract_urls(text):
    url_pattern = re.compile(r'http[s]?://(?:[a-zA-Z]|[0-9]|[$-_@.&+]|[!*\\(\\),]|(?:%[0-9a-fA-F][0-9a-fA-F]))+')
    return re.findall(url_pattern, text)