DD
DevDash

Regex for Absolute URL

Regex Pattern

^[a-zA-Z][a-zA-Z0-9+.-]*:\/\/[^\s]+$

Absolute URL with any protocol scheme

Quick Answer

The regex pattern for absolute url is `^[a-zA-Z][a-zA-Z0-9+.-]*:\/\/[^\s]+$`. Absolute URL with any protocol scheme. This works in JavaScript, Python, Ruby, PHP, Java, and most regex engines that support PCRE syntax.

Test Examples

InputResult
https://example.com✓ Matches
ftp://files.com/path✓ Matches
ws://socket.io:8080✓ Matches
/relative/path✗ No match
example.com✗ No match
://no-scheme✗ No match

Code Examples

javascript

const regex = /^[a-zA-Z][a-zA-Z0-9+.-]*:\\/\\/[^\s]+$/;
const isValid = regex.test(value);

python

import re
pattern = r'^[a-zA-Z][a-zA-Z0-9+.-]*:\/\/[^\s]+$'
if re.match(pattern, value):
    print("valid")

ruby

pattern = /^[a-zA-Z][a-zA-Z0-9+.-]*:\/\/[^\s]+$/
if value =~ pattern
  puts "valid"
end

php

if (preg_match('/^[a-zA-Z][a-zA-Z0-9+.-]*:\\/\\/[^\s]+$/', $value)) {
    echo "valid";
}

java

String pattern = "^[a-zA-Z][a-zA-Z0-9+.-]*:\\/\\/[^\\s]+$";
boolean isValid = value.matches(pattern);

Frequently Asked Questions

Related Regex Patterns

Want API access + no ads? Pro coming soon.