createSafeMatcher
Like createMatcher, but returns null instead of throwing when a string pattern is an
invalid regular expression, to report bad user input without a try.
Available since v3.1.5
Import
Section titled “Import”Signature
Section titled “Signature”Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
pattern | MatcherPattern | readonly MatcherPattern[] | A pattern, or an array of patterns and exclusions |
options | MatcherOptions | Syntax of string patterns and case sensitivity — see MatcherOptions (optional) |
Returns
Section titled “Returns”function | null — A function telling whether a string matches, or null for an invalid regular expression
Examples
Section titled “Examples”Validate a user filter
Section titled “Validate a user filter”An invalid regular expression gives null, to report it without a try.
Use it like createMatcher
Section titled “Use it like createMatcher”For valid patterns, the result is the same predicate.
Related Types
Section titled “Related Types”MatcherOptions
Section titled “MatcherOptions”Options for createMatcher and createSafeMatcher.
MatcherPattern
Section titled “MatcherPattern”One pattern accepted by createMatcher: a string (read according to
MatcherOptions.syntax), a RegExp, or a predicate of your own.
