from bs4 import BeautifulSoup
import re


def scrape_urls(html_text, pattern):
    """Extract URLs from raw html based on regex pattern"""
    soup = BeautifulSoup(html_text,"html.parser")
    anchors = soup.find_all("a")
    urls = [a.get("href") for a in anchors]
    return [url for url in urls if re.match(pattern, url)!=None]