URL Extraction Function

  • Share this:

Code introduction


Extract all URLs from the given text.


Technology Stack : os, re, sys, json, time, random

Code Type : Function

Code Difficulty : Intermediate


                
                    
import os
import re
import sys
import json
import time
import random

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