~/devtools / regex / url
tool::regex-guide

regex url

/^https?:\/\/[^\s\/$.?#].[^\s]*$/i

URL Validation

ad · 728×90
Regex Pattern
/^https?:\/\/[^\s\/$.?#].[^\s]*$/i
Flags:i
Pattern Breakdown
^https?http or https scheme
:\/\/Literal ://
[^\s\/$.?#]First domain char: not whitespace, slash, dot, $, ?, #
.Any single character
[^\s]*Rest of URL: any non-whitespace characters
$End of string
Matching Examples
https://example.com
http://sub.domain.org/path?q=1
https://api.site.io/v1/users
Non-Matching Examples
ftp://file.server.com
example.com
https://
//no-scheme.com

Validates URLs starting with http or https. Allows standard URL components including domain, path, and query string. Other schemes like ftp or mailto require separate patterns.

Language Usage

JavaScriptUse RegExp object or literal syntax
const pattern = /^https?:\/\/[^\s\/$.?#].[^\s]*$/i;

// Test a string
console.log(pattern.test("https://example.com")); // true
console.log(pattern.test("ftp://file.server.com")); // false

// Match and extract
const result = "https://example.com".match(pattern);
PythonUse the re module
import re

pattern = r"^https?:\/\/[^\s\/$.?#].[^\s]*$"
flags = re.IGNORECASE

# Test a string
if re.fullmatch(pattern, "https://example.com", flags):
    print("Valid")

# Find all matches in text
matches = re.findall(pattern, text, flags)
JavaUse java.util.regex package
import java.util.regex.*;

String pattern = "^https?:\\/\\/[^\\s\\/$.?#].[^\\s]*$";
Pattern p = Pattern.compile(pattern, Pattern.CASE_INSENSITIVE);

Matcher m = p.matcher("https://example.com");
boolean isValid = m.matches(); // true

// Find occurrences
Matcher finder = p.matcher(inputText);
while (finder.find()) {
    System.out.println(finder.group());
}

Common Use Cases

  • Validate website URL input fields
  • Filter valid URLs from a list of links
  • Pre-validate URL format in web crawlers
  • Validate homepage URL in user profiles
  • Verify webhook URLs before registration

Related Patterns

email/^[a-zA-Z0-9._%+\-]+@[a-zA-Z0-9.\-]+\.[a-/iphone/^\+?[\d\s\-\(\)]{7,15}$/ip-address/^((25[0-5]|2[0-4]\d|1\d{2}|[1-9]\d|\d)\./date/^\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12]\d|3[/
ad · 300×250
Back to Regex Tester
// related tools
Cron Expression Generator
Build and parse cron expressions visually. Generate human-readable descriptions and preview next execution times.
jwt
JWT Decoder
Decode and inspect JWT tokens. View header, payload, and signature details.
Color Converter
Convert colors between HEX, RGB, HSL, and more. Pick colors visually.
ts
Timestamp Converter
Convert Unix timestamps to human-readable dates. Supports ms/s, UTC/local, and relative time.