1.1.0 • Published 5 months ago

@savagechieftain/regext v1.1.0

Weekly downloads
-
License
MIT
Repository
github
Last release
5 months ago

RegExt - Extended Regular Expression Class

npm version Release License: MIT TypeScript

  • RegExt is a TypeScript library that provides convenient utility methods by extending JavaScript's standard RegExp class.
  • It offers complete TypeScript support and type safety.

Features

  • 🚀 Full TypeScript support
  • 📦 ES Modules & CommonJS support
  • 🔧 Rich extension methods
  • 🛡️ Type-safe operations
  • 📝 Comprehensive JSDoc documentation

Installation

npm install regext

Usage

ES Modules (TypeScript/JavaScript)

import RegExt from 'regext';

// Full type support in TypeScript
const regex = new RegExt('\\d+', 'g');
const numbers: string[] = regex.extract('abc123def456');
console.log(numbers); // ['123', '456']

CommonJS

const RegExt = require('regext').default;

TypeScript

import RegExt from 'regext';

Quick Start

import RegExt from 'regext';

const regex = new RegExt('\\d+', 'g');

// Extract all numbers from text
const numbers = regex.extract('Price: $29.99, Tax: $3.50');
console.log(numbers); // ['29', '99', '3', '50']

// Count matches
const count = regex.count('123 456 789');
console.log(count); // 3

// Safe testing without affecting lastIndex
const hasNumbers = regex.safeTest('abc123');
console.log(hasNumbers); // true

Methods Overview

  • loopExec(str) - Get all matches with infinite loop prevention
  • safeTest(str) - Test without modifying lastIndex
  • extract(str) - Extract matched strings as array
  • extractGroups(str) - Extract capture groups
  • replaceAll(str, replacement) - Replace all matches
  • replaceFirst(str, replacement) - Replace first match only
  • count(str) - Count number of matches
  • findLast(str) - Get the last match

Documentation

License

MIT