AntPathMatcher class

The PathMatcher for Ant-style patterns, the syntax of locations such as resources*:i18n/**/*.properties.

  • ? matches one character, * zero or more characters within a segment, ** zero or more whole segments;
  • {name} captures part of a segment, {name:regex} only when it matches the regular expression.

The separator is / unless given, so the same matcher works for dotted names. Applications rarely create one; resource patterns use it already.

final matcher = AntPathMatcher();
matcher.match('config/**/*.properties', 'config/dev/app.properties');
matcher.extractUriTemplateVariables(
  '/users/{id:\\d+}',
  '/users/42',
); // {'id': '42'}

final dots = AntPathMatcher(pathSeparator: '.');
dots.match('app.*.enabled', 'app.cache.enabled'); // true

Spring (Java):

var matcher = new AntPathMatcher();
matcher.match("config/**/*.properties", "config/dev/app.properties");
matcher.extractUriTemplateVariables("/users/{id:\\d+}", "/users/42");

var dots = new AntPathMatcher(".");
dots.match("app.*.enabled", "app.cache.enabled");
Implemented types

Constructors

AntPathMatcher({String pathSeparator = defaultPathSeparator, bool caseSensitive = true, bool trimTokens = false})
Creates a matcher that splits paths at pathSeparator (/ unless given), compares segments case-sensitively unless caseSensitive is false, and ignores whitespace around segments when trimTokens is true.

Properties

cachedPatternCount → int
How many compiled segment patterns are cached now, for tests and diagnostics.
no setter
caseSensitive → bool
Whether segments are compared case-sensitively (default true).
final
hashCode → int
The hash code for this object.
no setterinherited
pathSeparator → String
The text between path segments.
final
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited
trimTokens → bool
Whether whitespace around segments is ignored (default false).
final

Methods

combine(String pattern1, String pattern2) → String
Joins two patterns into one, such as a prefix and a sub-pattern: /hotels/* and /booking give /hotels/booking.
override
extractPathWithinPattern(String pattern, String path) → String
The part of path matched by the wildcard part of pattern, such as the file path below a mapped directory.
override
extractUriTemplateVariables(String pattern, String path) → Map<String, String>
The values of the {name} variables of pattern in path, by name.
override
getPatternComparator(String path) → Comparator<String>
A comparator that sorts patterns from the most to the least specific for path, to pick the best of several matching patterns. A pattern equal to path comes first and /** last.
override
isPattern(String path) → bool
Whether path contains pattern syntax (*, ? or a {name} variable), so it must be matched rather than compared.
override
match(String pattern, String path) → bool
Whether the whole of path matches pattern.
override
matchStart(String pattern, String path) → bool
Whether path matches the beginning of pattern, so a longer path starting with it could still match. Used to skip directories that cannot contain a match.
override
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() → String
A string representation of this object.
inherited

Operators

operator ==(Object other) → bool
The equality operator.
inherited

Constants

cacheTurnoffThreshold → const int
How many compiled segment patterns are cached before caching is turned off, as Spring's AntPathMatcher.CACHE_TURNOFF_THRESHOLD does: that many distinct patterns means they are generated, so the cache would only grow.
defaultPathSeparator → const String
The default separator, /.