@ts-utilkit/regex
v0.2.0
Published
Regular expression utilities for pattern matching and text processing
Downloads
130
Maintainers
Readme
@ts-utilkit/regex
regex Functions - TypeScript utility functions for regex operations.
Installation
npm install @ts-utilkit/regexFeatures
- 🚀 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
Available Functions (15)
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
Quick Example
import {
escapeRegExp,
extractURLsFromText,
isMatchingPattern,
} from '@ts-utilkit/regex';
escapeRegExp('Price: $10.99'); // 'Price: \$10\.99'
extractURLsFromText('Visit https://a.com'); // ['https://a.com']
isMatchingPattern('[email protected]', /^\S+@\S+\.\S+$/); // trueLicense
MIT © Mykyta Forofontov
Contributing
Contributions are welcome! Please see the main repository for contribution guidelines.
