UI Bakery RegEx Library
About UI Bakery
Try UI Bakery for Free ↗
RegEx library
Email regex Python
Phone number regex Python
IP address regex Python
Date regex Python
URL regex Python
Numbers only regex (digits only) Python
UUID regex Python
Regex match words Python
ZIP code regex Python
GUID regex Python
Password regex Python
HTML regex Python
SSN regex Python
XML regex Python
Mac address regex Python
Street address regex Python

URL regex Python

URL regular expressions can be used to verify if a string has a valid URL format as well as to extract an URL from a string.

Discover UI Bakery – an intuitive visual internal tools builder. Try it now!

JavaScript
Python
Java
C#
PHP

URL regex that starts with HTTP or HTTPS

HTTP and HTTPS URLs that start with protocol can be validated using the following regular expression

"^https?:\\/\\/(?:www\\.)?[-a-zA-Z0-9@:%._\\+~#=]{1,256}\\.[a-zA-Z0-9()]{1,6}\\b(?:[-a-zA-Z0-9()@:%_\\+.~#?&\\/=]*)$"
Test it!
/^https?:\/\/(?:www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b(?:[-a-zA-Z0-9()@:%_\+.~#?&\/=]*)$/

True

False

Enter a text in the input above to see the result

Example code in Python:

import re

# Validate URL
url_pattern = "^https?:\\/\\/(?:www\\.)?[-a-zA-Z0-9@:%._\\+~#=]{1,256}\\.[a-zA-Z0-9()]{1,6}\\b(?:[-a-zA-Z0-9()@:%_\\+.~#?&\\/=]*)$"
re.match(url_pattern, 'https://uibakery.io') # Returns Match object
re.match(url_pattern, 'https:/uibakery.io') # Returns None

# Extract URL from a string
url_extract_pattern = "https?:\\/\\/(?:www\\.)?[-a-zA-Z0-9@:%._\\+~#=]{1,256}\\.[a-zA-Z0-9()]{1,6}\\b(?:[-a-zA-Z0-9()@:%_\\+.~#?&\\/=]*)"
re.findall(url_extract_pattern, 'You can view more details at https://uibakery.io or just ping via email.') # returns ['https://uibakery.io']

URL regex that doesn’t start with HTTP or HTTPS

The regular expression to validate URL without protocol is very similar:

"^[-a-zA-Z0-9@:%._\\+~#=]{1,256}\\.[a-zA-Z0-9()]{1,6}\\b(?:[-a-zA-Z0-9()@:%_\\+.~#?&\\/=]*)$"
Test it!
/^[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b(?:[-a-zA-Z0-9()@:%_\+.~#?&\/=]*)$/

True

False

Enter a text in the input above to see the result

Example code in Python:

# Validate URL without protocol
url_pattern = "^[-a-zA-Z0-9@:%._\\+~#=]{1,256}\\.[a-zA-Z0-9()]{1,6}\\b(?:[-a-zA-Z0-9()@:%_\\+.~#?&\\/=]*)$"
re.match(url_pattern, 'uibakery.io/contact') # Returns Match object
re.match(url_pattern, '/uibakery.io') # Returns None

# Extract URL without prrotocol from a string
url_extract_pattern = "[-a-zA-Z0-9@:%._\\+~#=]{1,256}\\.[a-zA-Z0-9()]{1,6}\\b(?:[-a-zA-Z0-9()@:%_\\+.~#?&\\/=]*)"
re.findall(url_extract_pattern, 'You can view more details at uibakery.io or just ping via email.') # returns ['uibakery.io']
Test it!

True

False

Enter a text in the input above to see the result

Notes on URL validation

The above-mentioned regular expressions only cover the most commonly used types of URLs with domain names. If you have some more complex cases you might need a different solution.

Create an internal tool with UI Bakery

Discover UI Bakery – an intuitive visual internal tools builder.

Try UI Bakery ↗