Pattern class

Pattern that is used to match a path.

A pattern is used in a ServerRule to determine which HTTP requests the rule will process. If the path of the HTTP request matches the pattern, the rule will apply. Otherwise, the rule won't apply.

The string representation of a pattern always starts with a tilde ("~") to indicate it is a pattern.

Like a path, a pattern consists of a sequence of segments separated by a slash ("/") character. But there are four types of segments in a pattern:

  • literal segments
  • variable segments (value starts with a colon ":")
  • optional segments (value ends with a question mark "?")
  • wildcard segments (entire value is a single asterisk "*")

The segment types cannot be combined. For example, ":foo?" is not allowed.

A pattern can have at most one wildcard segment. The behaviour is undefined if there are two or more wildcard segments.

See the match method for how the different types of segments match a path.

Constructors

Pattern(String pattern)
Constructor from a string representation of a path pattern.

Properties

hashCode int
The hash code for this object.
no setteroverride
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

compareTo(Pattern other) int
Comparing two patterns for ordering them.
match(List<String> components) RequestParams?
Matches a path to the pattern.
matchesSamePaths(Pattern other) bool
Checks if two patterns will match the exact same set of paths.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() String
A string representation of this object.
override

Operators

operator ==(Object other) bool
The equality operator.
override

Constants

wildcard → const String
Segment name for the wildcard segment.