Regular Expressions 101

Community Patterns

1...456

URL Regex

2

Regular Expression
.NET 7.0 (C#)

@"
^(?>(?'protocol'[a-zA-Z]+)://)?(?'domain'[a-zA-Z0-9.\-_]*)?(?>:(?'port'\d{1,5}))?/(?'path'[a-zA-Z0-9_\-%]+)(?:(?>\?(?'query'[a-zA-Z0-9_\-=&%]+))()|(?>#(?'anchor'[a-zA-Z0-9_\-%]+))()){0,2}$
"
gm

Description

Matches protocol, domain, port, path, query and anchor as named capturing groups.

Submitted by Jonathan - 10 months ago (Last modified 10 months ago)