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

Text Search Utility

Build a text search utility that finds exact matches of user-provided search terms within larger text documents, even when the search terms contain special characters.

Requirements

Your utility must support searching for literal text strings that may contain any characters including those that have special meaning in regular expressions (such as ., *, ?, $, +, [, ], (, ), {, }, |, ^, \, and -).

The search should:

  • Find exact literal matches of the search term in the target text
  • Support case-sensitive and case-insensitive search modes
  • Return all matching positions or a boolean indicating if a match was found
  • Handle Unicode characters and emojis correctly

Implementation

@generates

API

/**
 * Searches for a literal text string within a target string
 * @param {string} searchTerm - The literal text to search for
 * @param {string} targetText - The text to search within
 * @param {Object} options - Search options
 * @param {boolean} options.caseSensitive - Whether search is case-sensitive (default: true)
 * @returns {boolean} True if the search term is found, false otherwise
 */
function searchText(searchTerm, targetText, options = { caseSensitive: true });

/**
 * Finds all matches of a literal text string within a target string
 * @param {string} searchTerm - The literal text to search for
 * @param {string} targetText - The text to search within
 * @param {Object} options - Search options
 * @param {boolean} options.caseSensitive - Whether search is case-sensitive (default: true)
 * @returns {Array<string>} Array of all matches found
 */
function findAllMatches(searchTerm, targetText, options = { caseSensitive: true });

Test Cases

Basic search with special characters

  • Searching for "$100" in "The price is $100 today" with case-sensitive mode returns true @test
  • Searching for "file.txt" in "Open file.txt now" with case-sensitive mode returns true @test

Case-insensitive search

  • Searching for "Mr. Smith" in "Looking for mr. smith" with case-insensitive mode returns true @test

Find all matches

  • Finding all matches of "$.99" in "Items cost $.99, $.99, and $1.00" returns ["$.99", "$.99"] @test

Complex special characters

  • Searching for "[urgent]" in "Message: [urgent] reply needed" returns true @test

Dependencies { .dependencies }

escape-string-regexp { .dependency }

Provides string escaping for safe use in regular expressions.

@satisfied-by

Install with Tessl CLI

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

tile.json