Skip to main content

Regex Inventory

warning

This inventory was generated by Copilot's “Claude Sonnet 4 (Preview)” and has not yet been verified by a human.

1. Space and Character Replacement Patterns

/\s+/g - Space Regex

  • File: index.js - Line 48
  • Usage: Used for replacing spaces in term names and spec names when creating IDs and references
  • Context: Applied to normalize identifiers like primary.replace(spaceRegex, '-').toLowerCase()
  • Original Spec-Up: Also part of the original Spec-Up

/^\s*~\s*/ - Tilde Line Prefix

  • File: assets/js/insert-trefs.js - Line 102
  • Usage: Removes leading tilde (~) and spaces from content lines in term definitions
  • Context: Part of content cleaning when processing external term references
  • Original Spec-Up: Not part of the original Spec-Up

2. Template and Tag Processing Patterns

/\[\[\s*([^\s\[\]:]+):?\s*([^\]\n]+)?\]\]/img - Template Replacer Regex

  • File: index.js - Line 174
  • Usage: Main regex for matching template tags like [[def: term]], [[xref: spec, term]], [[tref: spec, term]]
  • Context: Core pattern matching for all spec-up template substitutions
  • Original Spec-Up: Also part of the original Spec-Up

/\s*,+\s*/ - Template Arguments Separator

  • File: index.js - Line 175
  • Usage: Splits arguments within template tags (e.g., separating spec from term in [[xref: spec, term]])
  • Context: Used with replacerArgsRegex to parse template arguments
  • Original Spec-Up: Also part of the original Spec-Up

/\s*([^\s\[\]:]+):?\s*([^\]\n]+)?/i - Content Regex for Template Parsing

  • File: src/markdown-it-extensions.js - Line 10
  • Usage: Extracts template type and arguments from content between delimiters
  • Context: Parses the internal structure of template markers
  • Original Spec-Up: Also part of the original Spec-Up

3. External Reference Processing Patterns

/\[\[(?:xref|tref):.*?\]\]/g - External Reference Detector

  • File: src/collect-external-references.js - Line 82
  • Usage: Finds all xref and tref tags in markdown content for external reference collection
  • Context: Used to identify cross-references that need external repository data
  • Original Spec-Up: Not part of the original Spec-Up

/\[\[tref:([^,]+)/ - Tref Spec Name Extractor

  • File: src/health-check/term-references-checker.js - Line 16
  • Usage: Extracts spec name from tref tags in markdown files
  • Context: Health check validation of tref references
  • Original Spec-Up: Not part of the original Spec-Up

/\[\[tref:([^\]]+)\]\]/ - Complete Tref Content Extractor

  • File: src/health-check/tref-term-checker.js - Line 19
  • Usage: Extracts complete tref content including spec and term
  • Context: Term validation in health check system
  • Original Spec-Up: Not part of the original Spec-Up

4. Content Cleaning and Processing Patterns

/\[\[def:[^\]]*?\]\]/g - Definition Tag Remover

  • File: assets/js/insert-trefs.js - Line 100
  • Usage: Removes definition tags from external content before rendering
  • Context: Cleaning up transcluded content from external repositories
  • Original Spec-Up: Not part of the original Spec-Up

/\[\[ref:/g and /\]\]/g - Reference Tag Cleaners

  • File: assets/js/insert-trefs.js - Line 104-105
  • Usage: Removes reference markup from external content
  • Context: Part of content sanitization for external terms
  • Original Spec-Up: Not part of the original Spec-Up

5. Specification and File Processing Patterns

/^spec$|^spec-*\w+$/i - Spec Name Regex

  • File: index.js - Line 49
  • Usage: Matches specification names in various formats
  • Context: Validates and processes spec references in documentation
  • Original Spec-Up: Not part of the original Spec-Up

/^def$|^ref$|^xref|^tref$/i - Terminology Regex

  • File: index.js - Line 60
  • Usage: Matches terminology-related template types
  • Context: Filters template types for terminology processing
  • Original Spec-Up: Not part of the original Spec-Up, but this was the earlier version: /^def$|^ref$|^xref/i

6. Search and Highlighting Patterns

new RegExp(searchString, 'gi') - Dynamic Search Regex

  • File: assets/js/search.js - Line 285
  • Usage: Creates case-insensitive search pattern for in-page text highlighting
  • Context: Real-time search functionality in rendered specifications
  • Original Spec-Up: Not part of the original Spec-Up

7. URL and Path Processing Patterns

/(?:http[s]*:\/\/([^\/]*)|(?:\/([^\/?]*)))/g - Path Segment Regex

  • File: src/markdown-it-extensions.js - Line 129
  • Usage: Extracts domains and path segments from URLs for link styling
  • Context: Adds path-related attributes to links for enhanced styling and behavior
  • Original Spec-Up: Also part of the original Spec-Up

8. Notice and Container Processing Patterns

/(\w+)\s?(.*)?/ - Notice Parameters Matcher

  • File: index.js - Line 133
  • Usage: Validates and extracts parameters from notice containers (note, warning, example, etc.)
  • Context: Processing custom notice blocks in markdown content
  • Original Spec-Up: Also part of the original Spec-Up

Summary

The codebase uses approximately 15+ distinct regex patterns across various files, primarily for:

  • Template tag processing and substitution
  • External reference management
  • Content cleaning and sanitization
  • File and specification validation
  • Search functionality
  • URL processing and link enhancement

Most patterns follow a consistent approach of using capturing groups to extract specific parts of matched content, with case-insensitive flags commonly applied for flexibility.

File Purpose and Retention

This file (REGEX-INFO.md) should be retained because:

  1. Documentation Value: It provides a comprehensive overview of all regex patterns used in the codebase, which is essential for maintenance and debugging
  2. Developer Reference: New developers can quickly understand the regex patterns without having to search through the entire codebase
  3. Code Quality: Helps identify potential regex complexity issues and opportunities for refactoring
  4. SonarQube Compliance: Serves as documentation that can help with code analysis and review processes

How to Use This File

  • For Debugging: When encountering regex-related issues, reference this file to understand the pattern's purpose
  • For Development: Before adding new regex patterns, check if existing patterns can be reused
  • For Code Review: Use this as a reference when reviewing changes to regex patterns
  • For Refactoring: Identify patterns that might be duplicated or overly complex