URL Regex Pattern

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

Match and validate URLs with HTTP or HTTPS protocols. Supports query strings, fragments, and complex paths.

Test This Pattern →

Pattern Breakdown

Understanding the regex pattern https?:\/\/(www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_\+.~#?&//=]*):

  • ? - Optional (zero or one)
  • + - One or more
  • * - Zero or more
  • [...] - Character class
  • (...) - Capturing group
  • {n,m} - Quantifier (n to m times)

Examples

Input Result Explanation
https://example.com ✓ Match Basic HTTPS URL
http://www.example.com/path?query=1 ✓ Match Full URL with query
https://sub.domain.example.com:8080/path ✓ Match Subdomain with port
ftp://example.com ✗ No Match FTP protocol not matched

Code Examples

JavaScript

JavaScript
const pattern = /https?:\\/\\/(www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_\+.~#?&\/\/=]*)/;
const text = "https://example.com";

// Test if string matches
if (pattern.test(text)) {
  console.log("Valid!");
}

// Extract matches
const matches = text.match(pattern);
console.log(matches);

Python

Python
import re

pattern = r'https?:\/\/(www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_\+.~#?&//=]*)'
text = "https://example.com"

# Test if string matches
if re.match(pattern, text):
    print("Valid!")

# Find all matches
matches = re.findall(pattern, text)
print(matches)

PHP

PHP
<?php
$pattern = '/https?:\\/\\/(www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_\+.~#?&\/\/=]*)/';
$text = "https://example.com";

// Test if string matches
if (preg_match($pattern, $text)) {
    echo "Valid!";
}

// Find all matches
preg_match_all($pattern, $text, $matches);
print_r($matches);
?>

Java

Java
import java.util.regex.*;

String pattern = "https?:\\/\\/(www\\.)?[-a-zA-Z0-9@:%._\\+~#=]{1,256}\\.[a-zA-Z0-9()]{1,6}\\b([-a-zA-Z0-9()@:%_\\+.~#?&//=]*)";
String text = "https://example.com";

Pattern p = Pattern.compile(pattern);
Matcher m = p.matcher(text);

if (m.matches()) {
    System.out.println("Valid!");
}

Use Cases

Common applications: Link validation, content parsing, security checks

Frequently Asked Questions

What is the regex pattern for url regex pattern?
The regex pattern is: https?:\/\/(www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_\+.~#?&//=]*). Match and validate URLs with HTTP or HTTPS protocols. Supports query strings, fragments, and complex paths.
How do I use the url regex pattern pattern in JavaScript?
In JavaScript: const regex = new RegExp('https?:\\/\\/(www\\.)?[-a-zA-Z0-9@:%._\\+~#=]{1,256}\\.[a-zA-Z0-9()]{1,6}\\b([-a-zA-Z0-9()@:%_\\+.~#?&//=]*)'); or const regex = /https?:\\/\\/(www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_\+.~#?&\/\/=]*)/;
Does this pattern work in Python?
Yes, use: import re; pattern = re.compile(r'https?:\/\/(www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_\+.~#?&//=]*)') in Python. Most regex patterns are cross-language compatible.
What are common use cases for url regex pattern?
Link validation, content parsing, security checks

Related Regex Patterns

More Regex Tools

GetDevUtils offers a suite of developer tools including: