CtrlK
CommunityDocumentationLog inGet started
Tessl Logo

tessl/npm-escape-string-regexp

Escape RegExp special characters in strings for safe use in regular expressions

Overall
score

100%

Evaluation100%

1.00x

Agent success when using this tile

Overview
Eval results
Files

task.mdevals/scenario-5/

International Search Filter

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.

Requirements

Your utility should accept a search query string and return a RegExp object that:

  1. Handles international characters: Preserves Unicode characters including emojis, accented characters, and non-Latin scripts (Chinese, Arabic, Cyrillic, etc.) exactly as entered
  2. Escapes special characters: Prevents regex special characters in the query from being interpreted as regex syntax
  3. Case-insensitive matching: Creates a regex with the case-insensitive flag enabled
  4. Global matching: Creates a regex with the global flag enabled for finding all matches

The function should be named createSearchFilter and should:

  • Accept a single string parameter (the search query)
  • Return a RegExp object configured for global, case-insensitive matching
  • Throw an error if the input is not a string

Test Cases

  • It correctly handles emoji characters in search queries @test

    • Input: "Find 🦄 unicorn"
    • Should match: "Find 🦄 unicorn", "find 🦄 UNICORN"
    • Should preserve the emoji unmodified in the pattern
  • It escapes regex special characters in queries @test

    • Input: "price: $99.99?"
    • Should match: "price: $99.99?" (literal match)
    • Should not match: "price: A99B99C" ($ and ? not treated as regex syntax)
  • It preserves international characters from multiple scripts @test

    • Input: "café München 北京 مرحبا"
    • Should match: "Café MÜNCHEN 北京 مرحبا" (case-insensitive where applicable)
    • All non-Latin characters should remain unmodified
  • It throws an error for non-string input @test

    • Input: null, undefined, 123
    • Should throw an error

Implementation

@generates

API

/**
 * 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 };

Dependencies { .dependencies }

escape-string-regexp { .dependency }

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

tile.json