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

Text Search Utility

A utility for performing safe literal text searches in strings using regular expressions, with support for special characters and Unicode patterns.

Capabilities

Literal Text Search with Hyphen Characters

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.

  • Search for "2023-12-31" in "Date: 2023-12-31" returns true @test
  • Search for "foo-bar" in "The foo-bar method is deprecated" returns true @test
  • Search for "UTF-8" in "Encoding: UTF-16 or UTF-8" finds "UTF-8" @test
  • Search for "multi-word-phrase" in "This is a multi-word-phrase example" returns true @test

Case-Insensitive Search with Hyphens

Extend the search utility to support case-insensitive matching while maintaining proper hyphen handling.

  • Case-insensitive search for "UTF-8" matches "utf-8" @test
  • Case-insensitive search for "X-Ray" matches "x-ray" @test

Implementation

@generates

API

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

Dependencies { .dependencies }

escape-string-regexp { .dependency }

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

tile.json