Escape RegExp special characters in strings for safe use in regular expressions
Overall
score
100%
Evaluation — 100%
↑ 1.00xAgent success when using this tile
Build a search filtering utility that safely converts user search queries containing international text and special characters into valid regular expressions for case-insensitive pattern matching.
Your utility should accept a search query string and return a RegExp object that:
The function should be named createSearchFilter and should:
It correctly handles emoji characters in search queries @test
"Find 🦄 unicorn""Find 🦄 unicorn", "find 🦄 UNICORN"It escapes regex special characters in queries @test
"price: $99.99?""price: $99.99?" (literal match)"price: A99B99C" ($ and ? not treated as regex syntax)It preserves international characters from multiple scripts @test
"café München 北京 مرحبا""Café MÜNCHEN 北京 مرحبا" (case-insensitive where applicable)It throws an error for non-string input @test
null, undefined, 123@generates
/**
* Creates a RegExp for safe, case-insensitive searching of user queries
* that may contain international characters and special regex symbols.
*
* @param {string} query - The search query to convert into a regex pattern
* @returns {RegExp} A RegExp object with global and case-insensitive flags
* @throws {Error} If the query is not a string
*/
function createSearchFilter(query) {
// IMPLEMENTATION HERE
}
module.exports = { createSearchFilter };Provides safe escaping of regex special characters while preserving Unicode.
Install with Tessl CLI
npx tessl i tessl/npm-escape-string-regexp@5.0.0