URL Regex Python Validator

Search...

⌘K

URL Regex Python Validator

Search...

⌘K


URL Regex Python Validator

URL Regex Python Validator

Use the URL Regex Python Validator to accurately test patterns for validating website links in Python. Whether you’re checking for http, https, or complex paths, this tool helps ensure your URLs are clean, correct, and reliable. For more regex testing, explore the Python Regex Tester, Email Regex Python Validator, or IP Address Regex Python Validator.

https://www.admin.google.com/
Possible security issues
This regex appears to be safe.
Explanation
  • [A-Z]: uppercase letters
  • [a-z]: lowercase letters
  • [0-9]: digits
  • \.: a literal dot
  • +: one or more of the preceding
  • *: zero or more of the preceding
  • ?: optional (zero or one)
  • ^: start of string
  • $: end of string
Match information
Match 1: "https://www.admin.google.com/" at index 0
Test your APIs today!

Write in plain English — Qodex turns it into secure, ready-to-run tests.

Regular Expression - Documentation

What is the URL Regex Python Validator?


The URL Regex Python Validator is designed to help you check whether your regular expressions correctly match valid web addresses. This includes checking for:


  • Protocols like http or https

  • Domain names and subdomains

  • Optional ports, paths, query parameters, and fragments


It uses Python’s re module and is ideal for form validation, web crawling, data parsing, and link-checking tasks.


Common URL Regex Patterns


  1. Basic HTTP/HTTPS URL


    ^(http|https):\/\/[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$

    Matches: http://example.com, https://qodex.ai

    Does not match: example.com, ftp://server.com


  2. Full URL with Optional Paths & Queries


    ^(http|https):\/\/[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}(/[a-zA-Z0-9\-._~:/?#[\]@!$&'()*+,;=]*)?$

    Matches: https://site.com/path?search=value, http://domain.org


  3. With Optional Port


    ^(http|https):\/\/[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}(:\d{2,5})?(\/.*)?$

    Matches: http://localhost:8000/home, https://api.site.com:443/v1


Python Example Code


import re

def is_valid_url(url):
    pattern = re.compile(r'^(http|https):\/\/[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}(/[a-zA-Z0-9\-._~:/?#[\]@!$&\'()*+,;=]*)?$')
    return bool(pattern.fullmatch(url))

# Test URLs
print(is_valid_url("https://qodex.ai"))             # True
print(is_valid_url("http://example.com/path"))      # True
print(is_valid_url("ftp://invalid.com"))            # False

Try variations using the Python Regex Tester.


Use Cases


  • Form Validation: Ensure users submit well-structured URLs in web forms.

  • Data Cleaning: Remove or fix malformed links in large datasets.

  • Crawlers & Scrapers: Verify URLs before crawling or scraping content.

  • Security Filtering: Block suspicious or malformed URLs from being stored or executed.


Useful tools:


Categorized Regex Metacharacters 


  • ^ : Matches the start of the string

  • $ : Matches the end of the string

  • . : Matches any character (except newline)

  • + : Matches one or more of the previous token

  • * : Matches zero or more of the previous token

  • ? : Makes the preceding token optional

  • [] : Matches any one character inside the brackets

  • () : Groups patterns

  • | : OR operator

  • \: : Escapes special characters like ":"

Pro Tips

  • Always use raw strings (r'') in Python to avoid escaping issues.

  • Add anchors ^ and $ to match the full URL and avoid partial matches.

  • Use non-capturing groups (?:...) for cleaner matching if needed.

  • Test localhost or custom ports using a regex like: localhost:\d{2,5}

  • Combine this validator with IP Address Regex Python Validator for APIs or internal tools.


Frequently asked questions

Can I match localhost or internal domains?×
Yes. Adjust the regex to allow patterns like localhost or .local.
Does this support query parameters or fragments?+
What if I want to validate FTP or other protocols?+
Can this match URLs with trailing slashes?+
Can I use this in Django or Flask form validation?+