View source code Display the source code in std/path.d from which this page was generated on github. Improve this page Quickly fork, edit online, and submit a pull request for this page. Requires a signed-in GitHub account. This works well for small changes. If you'd like to make larger changes you may want to consider using local clone. Page wiki View or edit the community-maintained wiki page associated with this page.

Function std.path.globMatch

Matches a pattern against a path.

Some characters of pattern have a special meaning (they are meta-characters) and can't be escaped. These are:

* Matches 0 or more instances of any character. ? Matches exactly one instance of any character. [chars] Matches one instance of any character that appears between the brackets. [!chars] Matches one instance of any character that does not appear between the brackets after the exclamation mark. {string1string2} Matches either of the specified strings.

Individual characters are compared using filenameCharCmp!cs, where cs is an optional template parameter determining whether the comparison is case sensitive or not. See the filenameCharCmp documentation for details.

Note that directory separators and dots don't stop a meta-character from matching further portions of the path.

Prototype

bool globMatch(std.path.CaseSensitive cs, C, Range)(
  Range path,
  const(C)[] pattern
) pure nothrow @safe
if (isForwardRange!Range && isSomeChar!(ElementEncodingType!Range) && isSomeChar!C && is(Unqual!C == Unqual!(ElementEncodingType!Range)));

Returns

true if pattern matches path, false otherwise.

See also

Wikipedia: glob (programming)

Examples

assert (globMatch("foo.bar", "*"));
assert (globMatch("foo.bar", "*.*"));
assert (globMatch(foo/foo\bar, "f*b*r"));
assert (globMatch("foo.bar", "f???bar"));
assert (globMatch("foo.bar", "[fg]???bar"));
assert (globMatch("foo.bar", "[!gh]*bar"));
assert (globMatch("bar.fooz", "bar.{foo,bif}z"));
assert (globMatch("bar.bifz", "bar.{foo,bif}z"));

version (Windows)
{
    // Same as calling globMatch!(CaseSensitive.no)(path, pattern)
    assert (globMatch("foo", "Foo"));
    assert (globMatch("Goo.bar", "[fg]???bar"));
}
version (linux)
{
    // Same as calling globMatch!(CaseSensitive.yes)(path, pattern)
    assert (!globMatch("foo", "Foo"));
    assert (!globMatch("Goo.bar", "[fg]???bar"));
}

Authors

Lars Tandle Kyllingstad, Walter Bright, Grzegorz Adam Hankiewicz, Thomas Kühne, Andrei Alexandrescu

License

Boost License 1.0

Comments