@technobuddha > library > RegExp > Operations
Function: matches()
ts
function matches(text: string, match:
| string
| RegExp
| Iterable<
| string
| RegExp, any, any>): boolean;Defined in: matches.ts:24
Determines if the given text matches the provided match criteria.
The match parameter can be:
- A string: returns true if the trimmed, lowercased
textis equal to the lowercasedmatchstring. - A RegExp: returns true if the regular expression matches the trimmed, lowercased
text. - An iterable of strings or RegExps: returns true if any of the elements match the
textas described above.
Parameters
| Parameter | Type | Description |
|---|---|---|
text | string | The input string to test against the match criteria. |
match | | string | RegExp | Iterable< | string | RegExp, any, any> | A string, RegExp, or iterable of strings/RegExps to match against the input text. |
Returns
boolean
true if the text matches the criteria; otherwise, false.
Example
typescript
matches('Hello', 'hello'); // true
matches('Hello', /he.*/ui); // true
matches('Hello', ['hi', /he.*/ui]); // true
matches('Hello', ['hi', 'hey']); // false