CtrlK
CommunityDocumentationLog inGet started
Tessl Logo

tessl/npm-glob-to-regexp

tessl install tessl/npm-glob-to-regexp@0.4.0

Convert globs to regular expressions

Agent Success

Agent success rate when using this tile

100%

Improvement

Agent success rate improvement when using this tile compared to baseline

1.15x

Baseline

Agent success rate without this tile

87%

task.mdevals/scenario-8/

Pattern Validator

Build a pattern validator utility that checks if strings match specific patterns with character range requirements.

Requirements

Your task is to implement a pattern matching system that can validate strings against patterns containing character ranges. The system should support:

  1. Single character range matching: Match exactly one character from a specified set
  2. Numeric range validation: Match single digits from a numeric range (e.g., 0-9)
  3. Alphabetic range validation: Match single letters from an alphabetic range (e.g., a-z, A-Z)
  4. Mixed range patterns: Combine character ranges with literal text

The validator should handle patterns that specify exactly which characters are acceptable at specific positions in a string.

Functionality

Implement a validatePattern(pattern, testString) function that:

  • Takes a pattern string containing character range specifications
  • Returns true if the test string matches the pattern, false otherwise
  • Supports standard character range notation in patterns
  • Handles patterns with multiple ranges and literal characters

Test Cases

  • Pattern "file[0-9].txt" matches "file3.txt" but not "file10.txt" or "fileA.txt" @test
  • Pattern "test[a-z].js" matches "testx.js" but not "testX.js" or "test12.js" @test
  • Pattern "data[A-Z].csv" matches "dataM.csv" but not "datam.csv" or "data5.csv" @test
  • Pattern "page[0-5].html" matches "page2.html" and "page5.html" but not "page7.html" @test
  • Pattern "log[abc].txt" matches "loga.txt" and "logc.txt" but not "logd.txt" @test

Implementation

@generates

API

/**
 * Validates if a string matches a pattern with character range specifications.
 *
 * @param {string} pattern - The pattern to match against, containing character ranges
 * @param {string} testString - The string to validate
 * @returns {boolean} - true if testString matches pattern, false otherwise
 */
function validatePattern(pattern, testString) {
  // Implementation here
}

module.exports = { validatePattern };

Dependencies { .dependencies }

glob-to-regexp { .dependency }

Provides pattern to regular expression conversion capabilities.

@satisfied-by

Version

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
npmpkg:npm/glob-to-regexp@0.4.x
tile.json