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-4/

Dynamic Search Pattern Builder

Build a utility that creates safe regular expression patterns from user-provided search terms. The utility should handle various types of input strings and produce clean, minimal patterns suitable for searching text.

Requirements

Create a module that:

  1. Accepts a search term string and returns a pattern string that can be safely used in a RegExp
  2. Processes the search term to ensure special characters don't break the regex pattern
  3. Preserves non-special characters including Unicode characters, emojis, and international text
  4. Uses a minimal approach - only transforms characters that are absolutely necessary for regex safety
  5. Handles invalid inputs appropriately with meaningful error messages

The output should be a clean string that contains only the minimal necessary transformations to make the search term safe for use in regular expressions.

Implementation

Create the following files:

  • searchBuilder.js - Main module with search pattern building logic
  • searchBuilder.test.js - Test suite

Test Cases

Test 1: Basic special character handling { @test }

Input:

const term = "app.js";
// Build pattern and use in RegExp

Expected behavior: The pattern should match "app.js" but not "appXjs" when used in a RegExp.

Test 2: Multiple special characters { @test }

Input:

const term = "price: $19.99?";
// Build pattern and use in RegExp

Expected behavior: The pattern should match the exact string "price: $19.99?" and handle the $, ., and ? characters safely.

Test 3: Unicode preservation { @test }

Input:

const term = "café";
// Build pattern

Expected behavior: The pattern should match "café" exactly, with Unicode characters preserved unchanged.

Test 4: Invalid input { @test }

Input:

const term = null;
// Attempt to build pattern

Expected behavior: Should throw a TypeError with a meaningful message about expecting a string.

Dependencies { .dependencies }

escape-string-regexp { .dependency }

Provides safe regex pattern generation from strings.

Install with Tessl CLI

npx tessl i tessl/npm-escape-string-regexp@5.0.0

tile.json