regex Functions - TypeScript utility functions for regex operations.
npm install @ts-utilkit/regex- 🚀 TypeScript-first with complete type definitions
- ✅ Comprehensive test coverage (>95%)
- 📦 Tree-shakeable ESM and CommonJS support
- 🔒 Type-safe with strict TypeScript configuration
- 📖 Extensive JSDoc documentation
buildPattern- Builds a regex pattern from componentscombinePatterns- Combines multiple regex patterns with alternationcommonPatterns- Provides common regex patterns (email, URL, phone, etc.)countMatches- Counts the number of pattern matches in a stringextractMatchGroups- Extracts capture groups from regex matchesextractMatches- Extracts all matches of a pattern from textfindAll- Finds all occurrences of a pattern with positionsgetPatternComplexity- Analyzes regex pattern complexityhasBacktracking- Checks if a regex pattern has potential backtracking issueshighlightMatches- Highlights pattern matches in text with markersoptimizePattern- Optimizes regex pattern for better performancereplaceAll- Replaces all occurrences matching a patternreplaceWithCallback- Replaces matches using a callback functionsplitByPattern- Splits a string by a regex patterntestPattern- Tests if a string matches a regex pattern
import {
escapeRegExp,
extractURLsFromText,
isMatchingPattern,
} from '@ts-utilkit/regex';
escapeRegExp('Price: $10.99'); // 'Price: \$10\.99'
extractURLsFromText('Visit https://a.com'); // ['https://a.com']
isMatchingPattern('test@email.com', /^\S+@\S+\.\S+$/); // trueMIT © Mykyta Forofontov
Contributions are welcome! Please see the main repository for contribution guidelines.