Skip to content

matchGlob

Whether text matches a glob pattern in full: * matches any run of characters, ? exactly one. A one-shot shortcut for globToRegExp(pattern).test(text); to test many strings with the same pattern, build the RegExp once with globToRegExp or createGlobMatcher.

Available since v3.1.10

import { matchGlob } from '@helpers4/string';
// or, from the all-in-one package (same code, one install):
import { matchGlob } from 'helpers4/string';
matchGlob(pattern: string, text: string, options: MatchGlobOptions): boolean
ParameterTypeDescription
patternstringThe glob pattern
textstringThe string to test
optionsMatchGlobOptionsCase insensitivity and path globs — see MatchGlobOptions

boolean — true if text matches pattern

One call, with an option to ignore case.

matchGlob('screen *', 'Screen 2', { caseInsensitive: true }) // => true

Options for matchGlob and parsePatternOrRegExp.

interface MatchGlobOptions {
  caseInsensitive?: boolean;
  extended?: boolean;
}

View source on GitHub