Regular Expressions 101

Community Patterns

Community Library Entry

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 - a year ago (Last modified a year ago)