* Transforms the given text to a pattern, which does not match if the * text is only a part of a longer word. * * `\b` only asserts a boundary next to a word character, so it is only added * to the sides where the text itself begins or ends with one. Otherwise values * like `P@ssw0rd!` would ne
(text: string)
| 149 | * @returns {string} The resulting regular expression source |
| 150 | */ |
| 151 | function toExactMatchPattern(text: string): string { |
| 152 | const prefix = /^\w/.test(text) ? '\\b' : ''; |
| 153 | const suffix = /\w$/.test(text) ? '\\b' : ''; |
| 154 | return `${prefix}${escapeRegExp(text)}${suffix}`; |
| 155 | } |
no test coverage detected