Regex pattern explanation command #43

Closed
opened 2026-02-15 04:13:08 +03:00 by NiXTheDev · 0 comments
NiXTheDev commented 2026-02-15 04:13:08 +03:00 (Migrated from github.com)

Description

Add /explain command that breaks down regex patterns and explains what they match.

Use Case

Users often struggle to understand complex regex patterns. This command helps them learn regex syntax by explaining patterns in plain English.

Implementation Plan

  1. Create explain.ts module

    • Parse regex pattern into components
    • Generate human-readable explanations
    • Handle common patterns: quantifiers, groups, character classes, anchors
  2. Pattern parsing

    • Quantifiers: *, +, ?, {n,m}
    • Groups: () capture groups, (?:) non-capturing
    • Character classes: [a-z], \d, \w, etc.
    • Anchors: ^, $ for start/end
    • Escaped characters
  3. Output format (no emojis, clean text)

    Pattern: (\\d{3})-(\\d{2})-(\\d{4})
    
    Breakdown:
    - (\\d{3}) : Capture group - 3 digits
    - -         : Literal hyphen
    - (\\d{2}) : Capture group - 2 digits
    - -         : Literal hyphen
    - (\\d{4}) : Capture group - 4 digits
    
    Matches: Social Security Number format
    
  4. Integration

    • Add /explain command to bot
    • Accept pattern as argument
    • Handle invalid patterns gracefully
  5. Edge cases

    • Very long patterns (truncate)
    • Invalid regex syntax
    • Empty patterns

Acceptance Criteria

  • /explain command works with any regex pattern
  • Explanations are clear and accurate
  • No emojis in output
  • Handles invalid patterns gracefully
  • Tests for common patterns

Example Usage

User: /explain ^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$

Bot explains email pattern structure

Part of Epic #38

## Description Add /explain command that breaks down regex patterns and explains what they match. ## Use Case Users often struggle to understand complex regex patterns. This command helps them learn regex syntax by explaining patterns in plain English. ## Implementation Plan 1. **Create explain.ts module** - Parse regex pattern into components - Generate human-readable explanations - Handle common patterns: quantifiers, groups, character classes, anchors 2. **Pattern parsing** - Quantifiers: \*, +, ?, {n,m} - Groups: () capture groups, (?:) non-capturing - Character classes: [a-z], \\d, \\w, etc. - Anchors: ^, $ for start/end - Escaped characters 3. **Output format** (no emojis, clean text) ``` Pattern: (\\d{3})-(\\d{2})-(\\d{4}) Breakdown: - (\\d{3}) : Capture group - 3 digits - - : Literal hyphen - (\\d{2}) : Capture group - 2 digits - - : Literal hyphen - (\\d{4}) : Capture group - 4 digits Matches: Social Security Number format ``` 4. **Integration** - Add /explain command to bot - Accept pattern as argument - Handle invalid patterns gracefully 5. **Edge cases** - Very long patterns (truncate) - Invalid regex syntax - Empty patterns ## Acceptance Criteria - [ ] /explain command works with any regex pattern - [ ] Explanations are clear and accurate - [ ] No emojis in output - [ ] Handles invalid patterns gracefully - [ ] Tests for common patterns ## Example Usage User: /explain ^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,}$ Bot explains email pattern structure ## Related Part of Epic #38
Sign in to join this conversation.
No description provided.