Skip to content
ConsoleMonster
Class

GlobPattern

ConsoleMonster.Text

Namespace
ConsoleMonster.Text
Assembly
ConsoleMonster
Modifiers
sealed

A shell-style name pattern such as *.cs, report-??.csv or [a-c]*, for marking rows by pattern. Several patterns are separated with ; or , and match when any of them matches; ! before a pattern excludes what it matches (*.log;!debug*).

Inheritance

  • object
  • GlobPattern

Remarks

* matches any run of characters, ? one character, [abc] or [a-z] one character from the set and [!abc] one character outside it. A backslash escapes the next character only where it is not a path separator, so Windows paths are never patterns. Matching is linear in the text and never compiles a regular expression.

Constructors

public GlobPattern(string pattern, bool caseSensitive = false) #

Creates a pattern.

Parameters

pattern string required
One or more patterns separated by ; or ,.
caseSensitive bool = false optional
Whether letters must match case exactly; names are compared case-insensitively by default.

Methods

IsMatch 2 overloads
public bool IsMatch(string? text) #

Whether a name matches.

Parameters

text string? required
The name, usually a file name without its folder.

Returns

bool True when an included pattern matches and no excluded one does.
public static bool IsMatch(string pattern, string? text, bool caseSensitive = false) #

Whether a name matches a pattern; see GlobPattern.

Parameters

pattern string required
The pattern.
text string? required
The name.
caseSensitive bool = false optional
Whether letters must match case exactly.

Returns

bool True on a match.
public override string ToString() #

Returns a string that represents the current object.

Returns

string A string that represents the current object.

Properties

public string Pattern { get; } #

The pattern text as given.

public bool CaseSensitive { get; } #

Whether letters must match case exactly.