URL regex pattern

Copy and test a JavaScript regex for common URLs and links, with examples, limitations, and a one-click link to the regex tester.

URL regex pattern

Validate whole value

Use anchors to check whether the complete value matches.

Regex: ^(?:https?:\/\/|www\.)[^\s<>"']+$

Flags: i

Search in text

Find matching fragments inside a larger block of text.

Regex: \b(?:https?:\/\/|www\.)[^\s<>"']*[A-Za-z0-9/#]

Flags: gi

Examples that match

  • https://a11.tools/docs
  • www.example.org/help

Examples that do not match

  • ftp://example.com
  • example

Limitations

This pattern is intentionally practical and may still include trailing punctuation in edge cases.