Class URLPattern
- Namespace
- CSharpToJavaScript.APIs.JS
- Assembly
- CSharpToJavaScript.dll
The URLPattern interface of the {{domxref("URL Pattern API", "", "", "nocode")}} matches URLs or parts of URLs against a pattern. The pattern can contain capturing groups that extract parts of the matched URL.
[Value("URLPattern")]
public class URLPattern
- Inheritance
-
URLPattern
- Inherited Members
Remarks
More information about the syntax of patterns can be found on the API overview
page: {{domxref("URL Pattern API", "", "", "nocode")}}.
-A polyfill of URLPattern is available
on GitHub
-The pattern syntax used by URLPattern is similar to the syntax used by
path-to-regexp
Constructors
URLPattern()
public URLPattern()
URLPattern(Union154, URLPatternOptions)
The URLPattern() constructor returns a new URLPattern object representing the URLs that will be matched by this pattern.
public URLPattern(Union154 input = default, URLPatternOptions options = null)
Parameters
inputUnion154optionsURLPatternOptions
Remarks
-A polyfill of URLPattern is available
on GitHub
URLPattern(Union154, string, URLPatternOptions)
The URLPattern() constructor returns a new URLPattern object representing the URLs that will be matched by this pattern.
public URLPattern(Union154 input, string baseURL, URLPatternOptions options = null)
Parameters
inputUnion154baseURLstringoptionsURLPatternOptions
Remarks
-A polyfill of URLPattern is available
on GitHub
Properties
HasRegExpGroups
The hasRegExpGroups read-only property of the URLPattern interface is a boolean indicating whether or not any of the URLPattern components contain regular expression capturing groups.
[Value("hasRegExpGroups")]
public bool HasRegExpGroups { get; }
Property Value
- bool
A boolean.
Remarks
You can use the hasRegExpGroups property to check if a URLPattern object is usable with certain web platform APIs which do not allow regular expression capturing groups. For example:
Hash
The hash read-only property of the URLPattern interface is a string containing the pattern used to match the fragment part of a URL.
[Value("hash")]
public string Hash { get; }
Property Value
- string
A string.
Remarks
This is the normalized value of the hash pattern passed to the constructor, an inherited value from a baseURL passed to the constructor, or the default value ("*"), which matches any hash.
Hostname
The hostname read-only property of the URLPattern interface is a string containing the pattern used to match the hostname part of a URL.
[Value("hostname")]
public string Hostname { get; }
Property Value
- string
A string.
Remarks
This is the normalized value of the hostname pattern passed to the constructor, an inherited value from a baseURL passed to the constructor, or the default value ("*"), which matches any hostname.
Password
The password read-only property of the URLPattern interface is a string containing the pattern used to match the password part of a URL.
[Value("password")]
public string Password { get; }
Property Value
- string
A string.
Remarks
This is the normalized value of the password pattern passed to the constructor or the default value ("*"), which matches any password.
Pathname
The pathname read-only property of the URLPattern interface is a string containing the pattern used to match the pathname part of a URL.
[Value("pathname")]
public string Pathname { get; }
Property Value
- string
A string.
Remarks
This is the normalized value of the pathname pattern passed to the constructor, an inherited value from a baseURL passed to the constructor, or the default value ("*"), which matches any path.
Port
The port read-only property of the URLPattern interface is a string containing the pattern used to match the port part of a URL.
[Value("port")]
public string Port { get; }
Property Value
- string
A string.
Remarks
This is the normalized value of the port pattern passed to the constructor, or an inherited value from a baseURL passed to the constructor, or the default value ("*"), which matches any port.
Note that it may also be set implicitly to the empty string ("") if the pattern is specified using an url or baseURL string and the port is not explicitly set.
This empty string matches against URLs that use the default port (443).
Protocol
The protocol read-only property of the URLPattern interface is a string containing the pattern used to match the protocol part of a URL.
[Value("protocol")]
public string Protocol { get; }
Property Value
- string
A string.
Remarks
This is the normalized value of the protocol pattern passed to the constructor, an inherited value from a baseURL passed to the constructor, or the default value ("*"), which matches any protocol.
Search
The search read-only property of the URLPattern interface is a string containing the pattern used to match the search part of a URL.
[Value("search")]
public string Search { get; }
Property Value
- string
A string.
Remarks
This is the normalized value of the search pattern passed to the constructor, an inherited value from a baseURL passed to the constructor, or the default value ("*"), which matches any search part.
Username
The username read-only property of the URLPattern interface is a string containing the pattern used to match the username part of a URL.
[Value("username")]
public string Username { get; }
Property Value
- string
A string.
Remarks
This is the normalized value of the username pattern passed to the constructor, or the default value ("*"), which matches any username.
Methods
Exec(Union154, string)
The exec() method of the URLPattern interface takes a URL or object of URL parts, and returns either an object containing the results of matching the URL to the pattern, or null if the URL does not match the pattern.
[Value("exec")]
public URLPatternResult? Exec(Union154 input = default, string baseURL = null)
Parameters
Returns
- URLPatternResult
An Object that defines the matching elements and groups, or
nullif the passed inputs do not match the pattern.The object has the following properties:
Remarks
-A polyfill of URLPattern is available on GitHub
Test(Union154, string)
The test() method of the URLPattern interface takes a URL string or object of URL parts, and returns a boolean indicating if the given input matches the current pattern.
[Value("test")]
public bool Test(Union154 input = default, string baseURL = null)
Parameters
Returns
Remarks
-A polyfill of URLPattern is available
on GitHub