Escape RegExp special characters in strings for safe use in regular expressions
Overall
score
100%
Evaluation — 100%
↑ 1.00xAgent success when using this tile
A utility for performing safe literal text searches in strings using regular expressions, with support for special characters and Unicode patterns.
Build a search utility that can find literal text containing hyphens and special characters within larger strings. The utility should correctly handle cases where hyphens could be misinterpreted as character class ranges in regular expressions.
Extend the search utility to support case-insensitive matching while maintaining proper hyphen handling.
@generates
/**
* Search for a literal text pattern in a string
* @param {string} text - The text to search within
* @param {string} searchTerm - The literal text to search for
* @param {boolean} [caseInsensitive=false] - Whether to perform case-insensitive search
* @returns {boolean} True if the search term is found, false otherwise
*/
export function searchText(text, searchTerm, caseInsensitive = false);
/**
* Find all occurrences of a literal text pattern in a string
* @param {string} text - The text to search within
* @param {string} searchTerm - The literal text to search for
* @param {boolean} [caseInsensitive=false] - Whether to perform case-insensitive search
* @returns {string[]} Array of all matches found
*/
export function findAllMatches(text, searchTerm, caseInsensitive = false);Provides safe escaping of special characters in strings for use in regular expressions, with proper handling of hyphens for Unicode compatibility.
@satisfied-by
Install with Tessl CLI
npx tessl i tessl/npm-escape-string-regexp@5.0.0