Saltar al contenido
uencoder

Regex URL Patrones Referencia

Referencia para URL validation y parsing regex patrones para various URL formats.

URL Validation Patterns

A basic URL pattern: ^https?://[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}(/.*)?$ checks scheme, host, and optional path. More complete patterns include port, query, and fragment: ^https?://[^:/]+(:\d+)?(/[^?#]*)?(\?[^#]*)?(#.*)?$. Full RFC 3986 compliance is extremely complex and better handled with URL parsers. For validation, prefer the URL constructor (new URL()) over regex. Regex is useful for extracting URLs from text. The pattern https?://\S+ extracts URLs but may include trailing punctuation.

basic
Scheme + host + path
simple check
complete
Port, query, fragment
more parts
extraction
https?://\S+
from text

Protocol-Specific Patterns

HTTP/HTTPS: ^https?://... (web URLs). FTP: ^ftp://... (file transfer). WebSocket: ^wss?://... (WS protocol). File: ^file:///... (local files). Data: ^data:[a-z]+/[a-z]+;base64,... (embedded data). Magnet: ^magnet:\?xt=urn:btih:... (torrent). Custom schemes (myapp://) follow the same URI pattern. Internationalized domain names (IDN) contain Unicode and need Punycode for DNS. Always use the URL API for parsing; regex for extraction only.

http(s)
Web URLs
most common
ws(s)
WebSocket URLs
real-time
data:
Embedded data
base64

Herramientas relacionadas

参考链接