Regex tester / pattern library

Regex: url (http/https)

/https?:\/\/[\w.-]+(:\d+)?(\/[^\s?#]*)?(\?[^\s#]*)?(#\S*)?/g Test it live

How it works

Scheme, host, optional port, then optional path, query, and fragment — each segment stopping at whitespace. The g flag extracts every URL from a block of text rather than validating a single one.

Honest caveats

Extraction-grade, not validation-grade: it will happily grab a trailing punctuation mark glued to a URL in prose. For strict validation, parse with the URL constructor instead of a regex.

Matches

  • https://tarhun.dev/regex
  • http://localhost:8080/api?x=1
  • https://sub.example.co.uk#top

Doesn't match

  • ftp://server/file
  • www.example.com
  • https://

More patterns