nested-regex-groups
A lightweight TypeScript library that extends JavaScript's regular expressions with dot notation in capture group names to produce nested object structures.
Why?
Standard regex named capture groups return flat objects:
const match = 'john@example.com'.match(/^(?<name>\w+)@(?<domain>\w+\.\w+)$/);
console.log(match.groups);
// { name: 'john', domain: 'example.com' }
With nested-regex-groups, use dot notation to create nested structures:
import { rx } from 'nested-regex-groups/template';
const parser = rx`^(?<user.name>\w+)@(?<user.domain>\w+\.\w+)nested-regex-groups
A lightweight TypeScript library that extends JavaScript's regular expressions with dot notation in capture group names to produce nested object structures.
Why?
Standard regex named capture groups return flat objects:
const match = 'john@example.com'.match(/^(?<name>\w+)@(?<domain>\w+\.\w+)$/);
console.log(match.groups);
// { name: 'john', domain: 'example.com' }
With __INLINE_CODE_0__, use dot notation to create nested structures:
;
const result = parser('john@example.com');
console.log(result.value);
// { user: { name: 'john', domain: 'example.com' } }
Installation
npm install nested-regex-groups
Features
- Dot notation in capture group names:
(?<user.name>...)→{ user: { name: ... } } - Multiple pattern matching: Try patterns in priority order
- Zero dependencies: Tiny footprint
- Type-safe: Full TypeScript support with type inference
- Fast: Minimal overhead over native regex
- Composable: Build complex parsers from simple patterns
- Tree-shakeable: Import only what you need with modular exports
Modular Imports
The library supports selective imports for optimal bundle size, especially useful in buildless environments:
// Import only what you need
import { splitStatements } from 'nested-regex-groups/split-statements';
import { parsePatterns } from 'nested-regex-groups/parse-patterns';
// Or import everything (backward compatible)
import { splitStatements, parsePatterns } from 'nested-regex-groups';
Available Subpath Exports
Core Utilities:
nested-regex-groups/flat-to-nested- Convert dot-notation keys to nested objectsnested-regex-groups/merge-results- Merge multiple parse resultsnested-regex-groups/split-statements- Split paragraphs into statements
Core Parsing:
nested-regex-groups/nested-regex- Core parser with dot notation supportnested-regex-groups/try-patterns- Try multiple patterns + create parser factory
Runtime Pattern Parsing:
nested-regex-groups/parse-patterns- Parse patterns from strings/JSON config (includes parsePattern and parsePatterns)
Flat Group Parsing:
nested-regex-groups/parse-grouped-captures- Parse with flat groups (no nesting)nested-regex-groups/parse-grouped-capture-statements- Parse multiple statements with flat groups
Nested Statement Parsing:
nested-regex-groups/parse-pattern-statements- Parse multiple statements with nested groups
Template Tags:
nested-regex-groups/template- Template tag API (rx, rxPattern, rxParser)
Buildless Environment Example
<script type="module">
// Only loads split-statements.js (~1KB) instead of full library (~15KB)
import { splitStatements } from './node_modules/nested-regex-groups/split-statements.js';
const statements = splitStatements('First. Second. Third.');
console.log(statements); // ['First', 'Second', 'Third']
</script>
Quick Start
JSON Config (Recommended for Runtime)
Perfect for configuration-driven applications:
import { parsePatterns } from 'nested-regex-groups';
// Load from JSON file
const config = {
patterns: [
{
name: 'email',
pattern: '^(?<user.name>\\w+)@(?<user.domain>\\w+)
Template Tag (Recommended for Code)
The cleanest way for code-based patterns:
import { rx } from 'nested-regex-groups/template';
const parser = rx`^(?<person.name.first>\w+)\s+(?<person.name.last>\w+)nested-regex-groups
A lightweight TypeScript library that extends JavaScript's regular expressions with dot notation in capture group names to produce nested object structures.
Why?
Standard regex named capture groups return flat objects:
const match = 'john@example.com'.match(/^(?<name>\w+)@(?<domain>\w+\.\w+)$/);
console.log(match.groups);
// { name: 'john', domain: 'example.com' }
With __INLINE_CODE_0__, use dot notation to create nested structures:
import { rx } from 'nested-regex-groups/template';
const parser = rx`^(?<user.name>\w+)@(?<user.domain>\w+\.\w+)nested-regex-groups
A lightweight TypeScript library that extends JavaScript's regular expressions with dot notation in capture group names to produce nested object structures.
Why?
Standard regex named capture groups return flat objects:
const match = 'john@example.com'.match(/^(?<name>\w+)@(?<domain>\w+\.\w+)$/);
console.log(match.groups);
// { name: 'john', domain: 'example.com' }
With __INLINE_CODE_0__, use dot notation to create nested structures:
;
const result = parser('john@example.com');
console.log(result.value);
// { user: { name: 'john', domain: 'example.com' } }
Installation
npm install nested-regex-groups
Features
- Dot notation in capture group names: __INLINE_CODE_1__ → __INLINE_CODE_2__
- Multiple pattern matching: Try patterns in priority order
- Zero dependencies: Tiny footprint
- Type-safe: Full TypeScript support with type inference
- Fast: Minimal overhead over native regex
- Composable: Build complex parsers from simple patterns
- Tree-shakeable: Import only what you need with modular exports
Modular Imports
The library supports selective imports for optimal bundle size, especially useful in buildless environments:
// Import only what you need
import { splitStatements } from 'nested-regex-groups/split-statements';
import { parsePatterns } from 'nested-regex-groups/parse-patterns';
// Or import everything (backward compatible)
import { splitStatements, parsePatterns } from 'nested-regex-groups';
Available Subpath Exports
Core Utilities:
- __INLINE_CODE_3__ - Convert dot-notation keys to nested objects
- __INLINE_CODE_4__ - Merge multiple parse results
- __INLINE_CODE_5__ - Split paragraphs into statements
Core Parsing:
- __INLINE_CODE_6__ - Core parser with dot notation support
- __INLINE_CODE_7__ - Try multiple patterns + create parser factory
Runtime Pattern Parsing:
- __INLINE_CODE_8__ - Parse patterns from strings/JSON config (includes parsePattern and parsePatterns)
Flat Group Parsing:
- __INLINE_CODE_9__ - Parse with flat groups (no nesting)
- __INLINE_CODE_10__ - Parse multiple statements with flat groups
Nested Statement Parsing:
- __INLINE_CODE_11__ - Parse multiple statements with nested groups
Template Tags:
- __INLINE_CODE_12__ - Template tag API (rx, rxPattern, rxParser)
Buildless Environment Example
<script type="module">
// Only loads split-statements.js (~1KB) instead of full library (~15KB)
import { splitStatements } from './node_modules/nested-regex-groups/split-statements.js';
const statements = splitStatements('First. Second. Third.');
console.log(statements); // ['First', 'Second', 'Third']
</script>
Quick Start
JSON Config (Recommended for Runtime)
Perfect for configuration-driven applications:
import { parsePatterns } from 'nested-regex-groups';
// Load from JSON file
const config = {
patterns: [
{
name: 'email',
pattern: '^(?<user.name>\\w+)@(?<user.domain>\\w+)
Template Tag (Recommended for Code)
The cleanest way for code-based patterns:
;
const result = parser('John Doe');
if (result.success) {
console.log(result.value);
// { person: { name: { first: 'John', last: 'Doe' } } }
}
Multiple Patterns
import { rxParser, rxPattern } from 'nested-regex-groups/template';
const parser = rxParser([
rxPattern('email')`^(?<user.name>\w+)@(?<user.domain>\w+\.\w+)nested-regex-groups
A lightweight TypeScript library that extends JavaScript's regular expressions with dot notation in capture group names to produce nested object structures.
Why?
Standard regex named capture groups return flat objects:
const match = 'john@example.com'.match(/^(?<name>\w+)@(?<domain>\w+\.\w+)$/);
console.log(match.groups);
// { name: 'john', domain: 'example.com' }
With __INLINE_CODE_0__, use dot notation to create nested structures:
import { rx } from 'nested-regex-groups/template';
const parser = rx`^(?<user.name>\w+)@(?<user.domain>\w+\.\w+)nested-regex-groups
A lightweight TypeScript library that extends JavaScript's regular expressions with dot notation in capture group names to produce nested object structures.
Why?
Standard regex named capture groups return flat objects:
const match = 'john@example.com'.match(/^(?<name>\w+)@(?<domain>\w+\.\w+)$/);
console.log(match.groups);
// { name: 'john', domain: 'example.com' }
With __INLINE_CODE_0__, use dot notation to create nested structures:
;
const result = parser('john@example.com');
console.log(result.value);
// { user: { name: 'john', domain: 'example.com' } }
Installation
npm install nested-regex-groups
Features
- Dot notation in capture group names: __INLINE_CODE_1__ → __INLINE_CODE_2__
- Multiple pattern matching: Try patterns in priority order
- Zero dependencies: Tiny footprint
- Type-safe: Full TypeScript support with type inference
- Fast: Minimal overhead over native regex
- Composable: Build complex parsers from simple patterns
- Tree-shakeable: Import only what you need with modular exports
Modular Imports
The library supports selective imports for optimal bundle size, especially useful in buildless environments:
// Import only what you need
import { splitStatements } from 'nested-regex-groups/split-statements';
import { parsePatterns } from 'nested-regex-groups/parse-patterns';
// Or import everything (backward compatible)
import { splitStatements, parsePatterns } from 'nested-regex-groups';
Available Subpath Exports
Core Utilities:
- __INLINE_CODE_3__ - Convert dot-notation keys to nested objects
- __INLINE_CODE_4__ - Merge multiple parse results
- __INLINE_CODE_5__ - Split paragraphs into statements
Core Parsing:
- __INLINE_CODE_6__ - Core parser with dot notation support
- __INLINE_CODE_7__ - Try multiple patterns + create parser factory
Runtime Pattern Parsing:
- __INLINE_CODE_8__ - Parse patterns from strings/JSON config (includes parsePattern and parsePatterns)
Flat Group Parsing:
- __INLINE_CODE_9__ - Parse with flat groups (no nesting)
- __INLINE_CODE_10__ - Parse multiple statements with flat groups
Nested Statement Parsing:
- __INLINE_CODE_11__ - Parse multiple statements with nested groups
Template Tags:
- __INLINE_CODE_12__ - Template tag API (rx, rxPattern, rxParser)
Buildless Environment Example
<script type="module">
// Only loads split-statements.js (~1KB) instead of full library (~15KB)
import { splitStatements } from './node_modules/nested-regex-groups/split-statements.js';
const statements = splitStatements('First. Second. Third.');
console.log(statements); // ['First', 'Second', 'Third']
</script>
Quick Start
JSON Config (Recommended for Runtime)
Perfect for configuration-driven applications:
import { parsePatterns } from 'nested-regex-groups';
// Load from JSON file
const config = {
patterns: [
{
name: 'email',
pattern: '^(?<user.name>\\w+)@(?<user.domain>\\w+)
Template Tag (Recommended for Code)
The cleanest way for code-based patterns:
import { rx } from 'nested-regex-groups/template';
const parser = rx`^(?<person.name.first>\w+)\s+(?<person.name.last>\w+)nested-regex-groups
A lightweight TypeScript library that extends JavaScript's regular expressions with dot notation in capture group names to produce nested object structures.
Why?
Standard regex named capture groups return flat objects:
const match = 'john@example.com'.match(/^(?<name>\w+)@(?<domain>\w+\.\w+)$/);
console.log(match.groups);
// { name: 'john', domain: 'example.com' }
With __INLINE_CODE_0__, use dot notation to create nested structures:
import { rx } from 'nested-regex-groups/template';
const parser = rx`^(?<user.name>\w+)@(?<user.domain>\w+\.\w+)nested-regex-groups
A lightweight TypeScript library that extends JavaScript's regular expressions with dot notation in capture group names to produce nested object structures.
Why?
Standard regex named capture groups return flat objects:
const match = 'john@example.com'.match(/^(?<name>\w+)@(?<domain>\w+\.\w+)$/);
console.log(match.groups);
// { name: 'john', domain: 'example.com' }
With __INLINE_CODE_0__, use dot notation to create nested structures:
;
const result = parser('john@example.com');
console.log(result.value);
// { user: { name: 'john', domain: 'example.com' } }
Installation
npm install nested-regex-groups
Features
- Dot notation in capture group names: __INLINE_CODE_1__ → __INLINE_CODE_2__
- Multiple pattern matching: Try patterns in priority order
- Zero dependencies: Tiny footprint
- Type-safe: Full TypeScript support with type inference
- Fast: Minimal overhead over native regex
- Composable: Build complex parsers from simple patterns
- Tree-shakeable: Import only what you need with modular exports
Modular Imports
The library supports selective imports for optimal bundle size, especially useful in buildless environments:
// Import only what you need
import { splitStatements } from 'nested-regex-groups/split-statements';
import { parsePatterns } from 'nested-regex-groups/parse-patterns';
// Or import everything (backward compatible)
import { splitStatements, parsePatterns } from 'nested-regex-groups';
Available Subpath Exports
Core Utilities:
- __INLINE_CODE_3__ - Convert dot-notation keys to nested objects
- __INLINE_CODE_4__ - Merge multiple parse results
- __INLINE_CODE_5__ - Split paragraphs into statements
Core Parsing:
- __INLINE_CODE_6__ - Core parser with dot notation support
- __INLINE_CODE_7__ - Try multiple patterns + create parser factory
Runtime Pattern Parsing:
- __INLINE_CODE_8__ - Parse patterns from strings/JSON config (includes parsePattern and parsePatterns)
Flat Group Parsing:
- __INLINE_CODE_9__ - Parse with flat groups (no nesting)
- __INLINE_CODE_10__ - Parse multiple statements with flat groups
Nested Statement Parsing:
- __INLINE_CODE_11__ - Parse multiple statements with nested groups
Template Tags:
- __INLINE_CODE_12__ - Template tag API (rx, rxPattern, rxParser)
Buildless Environment Example
<script type="module">
// Only loads split-statements.js (~1KB) instead of full library (~15KB)
import { splitStatements } from './node_modules/nested-regex-groups/split-statements.js';
const statements = splitStatements('First. Second. Third.');
console.log(statements); // ['First', 'Second', 'Third']
</script>
Quick Start
JSON Config (Recommended for Runtime)
Perfect for configuration-driven applications:
import { parsePatterns } from 'nested-regex-groups';
// Load from JSON file
const config = {
patterns: [
{
name: 'email',
pattern: '^(?<user.name>\\w+)@(?<user.domain>\\w+)
Template Tag (Recommended for Code)
The cleanest way for code-based patterns:
;
const result = parser('John Doe');
if (result.success) {
console.log(result.value);
// { person: { name: { first: 'John', last: 'Doe' } } }
}
Multiple Patterns
,
rxPattern('username')`^(?<user.name>\w+)nested-regex-groups
A lightweight TypeScript library that extends JavaScript's regular expressions with dot notation in capture group names to produce nested object structures.
Why?
Standard regex named capture groups return flat objects:
const match = 'john@example.com'.match(/^(?<name>\w+)@(?<domain>\w+\.\w+)$/);
console.log(match.groups);
// { name: 'john', domain: 'example.com' }
With __INLINE_CODE_0__, use dot notation to create nested structures:
import { rx } from 'nested-regex-groups/template';
const parser = rx`^(?<user.name>\w+)@(?<user.domain>\w+\.\w+)nested-regex-groups
A lightweight TypeScript library that extends JavaScript's regular expressions with dot notation in capture group names to produce nested object structures.
Why?
Standard regex named capture groups return flat objects:
const match = 'john@example.com'.match(/^(?<name>\w+)@(?<domain>\w+\.\w+)$/);
console.log(match.groups);
// { name: 'john', domain: 'example.com' }
With __INLINE_CODE_0__, use dot notation to create nested structures:
;
const result = parser('john@example.com');
console.log(result.value);
// { user: { name: 'john', domain: 'example.com' } }
Installation
npm install nested-regex-groups
Features
- Dot notation in capture group names: __INLINE_CODE_1__ → __INLINE_CODE_2__
- Multiple pattern matching: Try patterns in priority order
- Zero dependencies: Tiny footprint
- Type-safe: Full TypeScript support with type inference
- Fast: Minimal overhead over native regex
- Composable: Build complex parsers from simple patterns
- Tree-shakeable: Import only what you need with modular exports
Modular Imports
The library supports selective imports for optimal bundle size, especially useful in buildless environments:
// Import only what you need
import { splitStatements } from 'nested-regex-groups/split-statements';
import { parsePatterns } from 'nested-regex-groups/parse-patterns';
// Or import everything (backward compatible)
import { splitStatements, parsePatterns } from 'nested-regex-groups';
Available Subpath Exports
Core Utilities:
- __INLINE_CODE_3__ - Convert dot-notation keys to nested objects
- __INLINE_CODE_4__ - Merge multiple parse results
- __INLINE_CODE_5__ - Split paragraphs into statements
Core Parsing:
- __INLINE_CODE_6__ - Core parser with dot notation support
- __INLINE_CODE_7__ - Try multiple patterns + create parser factory
Runtime Pattern Parsing:
- __INLINE_CODE_8__ - Parse patterns from strings/JSON config (includes parsePattern and parsePatterns)
Flat Group Parsing:
- __INLINE_CODE_9__ - Parse with flat groups (no nesting)
- __INLINE_CODE_10__ - Parse multiple statements with flat groups
Nested Statement Parsing:
- __INLINE_CODE_11__ - Parse multiple statements with nested groups
Template Tags:
- __INLINE_CODE_12__ - Template tag API (rx, rxPattern, rxParser)
Buildless Environment Example
<script type="module">
// Only loads split-statements.js (~1KB) instead of full library (~15KB)
import { splitStatements } from './node_modules/nested-regex-groups/split-statements.js';
const statements = splitStatements('First. Second. Third.');
console.log(statements); // ['First', 'Second', 'Third']
</script>
Quick Start
JSON Config (Recommended for Runtime)
Perfect for configuration-driven applications:
import { parsePatterns } from 'nested-regex-groups';
// Load from JSON file
const config = {
patterns: [
{
name: 'email',
pattern: '^(?<user.name>\\w+)@(?<user.domain>\\w+)
Template Tag (Recommended for Code)
The cleanest way for code-based patterns:
import { rx } from 'nested-regex-groups/template';
const parser = rx`^(?<person.name.first>\w+)\s+(?<person.name.last>\w+)nested-regex-groups
A lightweight TypeScript library that extends JavaScript's regular expressions with dot notation in capture group names to produce nested object structures.
Why?
Standard regex named capture groups return flat objects:
const match = 'john@example.com'.match(/^(?<name>\w+)@(?<domain>\w+\.\w+)$/);
console.log(match.groups);
// { name: 'john', domain: 'example.com' }
With __INLINE_CODE_0__, use dot notation to create nested structures:
import { rx } from 'nested-regex-groups/template';
const parser = rx`^(?<user.name>\w+)@(?<user.domain>\w+\.\w+)nested-regex-groups
A lightweight TypeScript library that extends JavaScript's regular expressions with dot notation in capture group names to produce nested object structures.
Why?
Standard regex named capture groups return flat objects:
const match = 'john@example.com'.match(/^(?<name>\w+)@(?<domain>\w+\.\w+)$/);
console.log(match.groups);
// { name: 'john', domain: 'example.com' }
With __INLINE_CODE_0__, use dot notation to create nested structures:
;
const result = parser('john@example.com');
console.log(result.value);
// { user: { name: 'john', domain: 'example.com' } }
Installation
npm install nested-regex-groups
Features
- Dot notation in capture group names: __INLINE_CODE_1__ → __INLINE_CODE_2__
- Multiple pattern matching: Try patterns in priority order
- Zero dependencies: Tiny footprint
- Type-safe: Full TypeScript support with type inference
- Fast: Minimal overhead over native regex
- Composable: Build complex parsers from simple patterns
- Tree-shakeable: Import only what you need with modular exports
Modular Imports
The library supports selective imports for optimal bundle size, especially useful in buildless environments:
// Import only what you need
import { splitStatements } from 'nested-regex-groups/split-statements';
import { parsePatterns } from 'nested-regex-groups/parse-patterns';
// Or import everything (backward compatible)
import { splitStatements, parsePatterns } from 'nested-regex-groups';
Available Subpath Exports
Core Utilities:
- __INLINE_CODE_3__ - Convert dot-notation keys to nested objects
- __INLINE_CODE_4__ - Merge multiple parse results
- __INLINE_CODE_5__ - Split paragraphs into statements
Core Parsing:
- __INLINE_CODE_6__ - Core parser with dot notation support
- __INLINE_CODE_7__ - Try multiple patterns + create parser factory
Runtime Pattern Parsing:
- __INLINE_CODE_8__ - Parse patterns from strings/JSON config (includes parsePattern and parsePatterns)
Flat Group Parsing:
- __INLINE_CODE_9__ - Parse with flat groups (no nesting)
- __INLINE_CODE_10__ - Parse multiple statements with flat groups
Nested Statement Parsing:
- __INLINE_CODE_11__ - Parse multiple statements with nested groups
Template Tags:
- __INLINE_CODE_12__ - Template tag API (rx, rxPattern, rxParser)
Buildless Environment Example
<script type="module">
// Only loads split-statements.js (~1KB) instead of full library (~15KB)
import { splitStatements } from './node_modules/nested-regex-groups/split-statements.js';
const statements = splitStatements('First. Second. Third.');
console.log(statements); // ['First', 'Second', 'Third']
</script>
Quick Start
JSON Config (Recommended for Runtime)
Perfect for configuration-driven applications:
import { parsePatterns } from 'nested-regex-groups';
// Load from JSON file
const config = {
patterns: [
{
name: 'email',
pattern: '^(?<user.name>\\w+)@(?<user.domain>\\w+)
Template Tag (Recommended for Code)
The cleanest way for code-based patterns:
;
const result = parser('John Doe');
if (result.success) {
console.log(result.value);
// { person: { name: { first: 'John', last: 'Doe' } } }
}
Multiple Patterns
]);
const result1 = parser('john@example.com');
// { success: true, pattern: 'email', value: { user: { name: 'john', domain: 'example.com' } } }
const result2 = parser('john');
// { success: true, pattern: 'username', value: { user: { name: 'john' } } }
API
Statements Parsing (Multiple Statements in Paragraphs)
Parse paragraphs containing multiple statements separated by periods, with support for nested object structures.
splitStatements(input)
Splits a paragraph into individual statements based on period delimiters.
import { splitStatements } from 'nested-regex-groups';
const statements = splitStatements('First. Second. Third.');
// ['First', 'Second', 'Third']
// Handles optional chaining and escaped periods
splitStatements('Check #obj?.prop. Use file\\.txt.');
// ['Check #obj?.prop', 'Use file.txt']
Rules:
- Splits on
. followed by whitespace or end of string
- Ignores
?. (optional chaining)
- Ignores
\. (escaped period - becomes . in output)
- Trailing period on last statement is optional
parseGroupedCaptures(input, patternConfigs, options?)
Parses a single statement using flat group patterns (no dots in group names).
import { parseGroupedCaptures } from 'nested-regex-groups';
const patterns = [
{ name: 'comparison', pattern: '^(?<trigger>on|off)\\s+when\\s+(?<lhs>#\\w+)\\s+eq\\s+(?<rhs>#\\w+)
Use when: You need flat objects without nesting.
parseGroupedCaptureStatements(input, patternConfigs, options?)
Parses multiple statements with flat group patterns.
import { parseGroupedCaptureStatements } from 'nested-regex-groups';
const patterns = [
{ name: 'comparison', pattern: '^(?<trigger>on|off)\\s+when\\s+(?<lhs>#\\w+)\\s+eq\\s+(?<rhs>#\\w+)
parsePatternStatements(input, patternConfigs, options?)
Parses multiple statements with nested group patterns (dots in group names).
import { parsePatternStatements } from 'nested-regex-groups';
const patterns = [
{ name: 'comparison', pattern: '^(?<trigger>on|off)\\s+when\\s+(?<lhs.id>#\\w+)\\s+eq\\s+(?<rhs.id>#\\w+)
Use when: You need nested objects from multiple statements.
Default Values
Both parsePatternStatements and parseGroupedCaptureStatements support default values for optional capture groups. This is useful when you want to provide fallback values for groups that might not match.
import { parsePatternStatements } from 'nested-regex-groups';
const patterns = [
{
name: 'comparison',
pattern: '^(?<trigger>on|off)?\\s*when\\s+(?<lhs.id>#\\w+)\\s+eq\\s+(?<rhs.id>#\\w+)
Key behaviors:
- Default values are applied when optional groups don't match (return
undefined)
- Parsed values always override defaults
- For nested patterns, use dot notation in default keys (e.g.,
'lhs.id': '#default')
- For flat patterns, use simple keys (e.g.,
trigger: 'on')
parseParagraph(input, patternConfigs, options?)
Convenience alias for parsePatternStatements (the most common use case).
import { parseParagraph } from 'nested-regex-groups';
const result = parseParagraph('on when #foo eq #bar. off when #baz.', patterns);
StatementsResult<T>
Return type for statements parsing functions:
interface StatementsResult<T = any> {
success: boolean; // true if all statements parsed successfully
statements: Array<{
pattern?: string; // Name of matched pattern
value?: T; // Parsed value (if successful)
error?: string; // Error message (if failed)
matched?: string; // Matched text
}>;
}
Example: Real-world be-switched paragraph
import { parsePatternStatements } from 'nested-regex-groups';
const patterns = [
{
name: 'fullComparison',
pattern: '^(?<trigger>on|off)\\s+when\\s+(?<lhs.id>#\\w+)(?:::(?<lhs.event>\\w+))?(?:\\?\\.(?<lhs.prop>\\w+))?\\s+(?<op>eq|gt|lt)\\s+(?<rhs.id>#\\w+)(?:::(?<rhs.event>\\w+))?(?:\\?\\.(?<rhs.prop>\\w+))?
See examples/statements-usage.ts for more examples.
Runtime Parsing (Recommended for JSON Config)
parsePattern(patternString, name?)
Parses a regex pattern string with dot notation and creates a parser. Perfect for loading patterns from JSON config files.
import { parsePattern } from 'nested-regex-groups';
// From JSON config
const config = { pattern: "^(?<user.name>\\w+)@(?<user.domain>\\w+)$" };
const parser = parsePattern(config.pattern);
const result = parser('john@example.com');
Parameters:
patternString: string - Regex pattern with dots in group names
name?: string - Optional name for error messages
Use when:
- Loading patterns from JSON files
- Patterns stored as strings in config
- Dynamic pattern loading at runtime
parsePatterns(patternConfigs, options?)
Creates a multi-pattern parser from JSON-like configuration objects.
import { parsePatterns } from 'nested-regex-groups';
const config = {
patterns: [
{ name: 'email', pattern: "^(?<user.name>\\w+)@(?<user.domain>\\w+)$" },
{ name: 'username', pattern: "^(?<user.name>\\w+)$" }
]
};
const parser = parsePatterns(config.patterns);
Use when:
- Loading multiple patterns from JSON
- Configuration-driven applications
- Patterns need to be updated without code changes
See JSON_CONFIG.md for complete guide.
Template Tag API (Recommended for Code)
rx
Template tag for creating single-pattern parsers with dot notation.
import { rx } from 'nested-regex-groups/template';
const parser = rx`^(?<user.name>\w+)@(?<user.domain>\w+)nested-regex-groups
A lightweight TypeScript library that extends JavaScript's regular expressions with dot notation in capture group names to produce nested object structures.
Why?
Standard regex named capture groups return flat objects:
const match = 'john@example.com'.match(/^(?<name>\w+)@(?<domain>\w+\.\w+)$/);
console.log(match.groups);
// { name: 'john', domain: 'example.com' }
With __INLINE_CODE_0__, use dot notation to create nested structures:
import { rx } from 'nested-regex-groups/template';
const parser = rx`^(?<user.name>\w+)@(?<user.domain>\w+\.\w+)nested-regex-groups
A lightweight TypeScript library that extends JavaScript's regular expressions with dot notation in capture group names to produce nested object structures.
Why?
Standard regex named capture groups return flat objects:
const match = 'john@example.com'.match(/^(?<name>\w+)@(?<domain>\w+\.\w+)$/);
console.log(match.groups);
// { name: 'john', domain: 'example.com' }
With __INLINE_CODE_0__, use dot notation to create nested structures:
;
const result = parser('john@example.com');
console.log(result.value);
// { user: { name: 'john', domain: 'example.com' } }
Installation
npm install nested-regex-groups
Features
- Dot notation in capture group names: __INLINE_CODE_1__ → __INLINE_CODE_2__
- Multiple pattern matching: Try patterns in priority order
- Zero dependencies: Tiny footprint
- Type-safe: Full TypeScript support with type inference
- Fast: Minimal overhead over native regex
- Composable: Build complex parsers from simple patterns
- Tree-shakeable: Import only what you need with modular exports
Modular Imports
The library supports selective imports for optimal bundle size, especially useful in buildless environments:
// Import only what you need
import { splitStatements } from 'nested-regex-groups/split-statements';
import { parsePatterns } from 'nested-regex-groups/parse-patterns';
// Or import everything (backward compatible)
import { splitStatements, parsePatterns } from 'nested-regex-groups';
Available Subpath Exports
Core Utilities:
- __INLINE_CODE_3__ - Convert dot-notation keys to nested objects
- __INLINE_CODE_4__ - Merge multiple parse results
- __INLINE_CODE_5__ - Split paragraphs into statements
Core Parsing:
- __INLINE_CODE_6__ - Core parser with dot notation support
- __INLINE_CODE_7__ - Try multiple patterns + create parser factory
Runtime Pattern Parsing:
- __INLINE_CODE_8__ - Parse patterns from strings/JSON config (includes parsePattern and parsePatterns)
Flat Group Parsing:
- __INLINE_CODE_9__ - Parse with flat groups (no nesting)
- __INLINE_CODE_10__ - Parse multiple statements with flat groups
Nested Statement Parsing:
- __INLINE_CODE_11__ - Parse multiple statements with nested groups
Template Tags:
- __INLINE_CODE_12__ - Template tag API (rx, rxPattern, rxParser)
Buildless Environment Example
<script type="module">
// Only loads split-statements.js (~1KB) instead of full library (~15KB)
import { splitStatements } from './node_modules/nested-regex-groups/split-statements.js';
const statements = splitStatements('First. Second. Third.');
console.log(statements); // ['First', 'Second', 'Third']
</script>
Quick Start
JSON Config (Recommended for Runtime)
Perfect for configuration-driven applications:
import { parsePatterns } from 'nested-regex-groups';
// Load from JSON file
const config = {
patterns: [
{
name: 'email',
pattern: '^(?<user.name>\\w+)@(?<user.domain>\\w+)
Template Tag (Recommended for Code)
The cleanest way for code-based patterns:
import { rx } from 'nested-regex-groups/template';
const parser = rx`^(?<person.name.first>\w+)\s+(?<person.name.last>\w+)nested-regex-groups
A lightweight TypeScript library that extends JavaScript's regular expressions with dot notation in capture group names to produce nested object structures.
Why?
Standard regex named capture groups return flat objects:
const match = 'john@example.com'.match(/^(?<name>\w+)@(?<domain>\w+\.\w+)$/);
console.log(match.groups);
// { name: 'john', domain: 'example.com' }
With __INLINE_CODE_0__, use dot notation to create nested structures:
import { rx } from 'nested-regex-groups/template';
const parser = rx`^(?<user.name>\w+)@(?<user.domain>\w+\.\w+)nested-regex-groups
A lightweight TypeScript library that extends JavaScript's regular expressions with dot notation in capture group names to produce nested object structures.
Why?
Standard regex named capture groups return flat objects:
const match = 'john@example.com'.match(/^(?<name>\w+)@(?<domain>\w+\.\w+)$/);
console.log(match.groups);
// { name: 'john', domain: 'example.com' }
With __INLINE_CODE_0__, use dot notation to create nested structures:
;
const result = parser('john@example.com');
console.log(result.value);
// { user: { name: 'john', domain: 'example.com' } }
Installation
npm install nested-regex-groups
Features
- Dot notation in capture group names: __INLINE_CODE_1__ → __INLINE_CODE_2__
- Multiple pattern matching: Try patterns in priority order
- Zero dependencies: Tiny footprint
- Type-safe: Full TypeScript support with type inference
- Fast: Minimal overhead over native regex
- Composable: Build complex parsers from simple patterns
- Tree-shakeable: Import only what you need with modular exports
Modular Imports
The library supports selective imports for optimal bundle size, especially useful in buildless environments:
// Import only what you need
import { splitStatements } from 'nested-regex-groups/split-statements';
import { parsePatterns } from 'nested-regex-groups/parse-patterns';
// Or import everything (backward compatible)
import { splitStatements, parsePatterns } from 'nested-regex-groups';
Available Subpath Exports
Core Utilities:
- __INLINE_CODE_3__ - Convert dot-notation keys to nested objects
- __INLINE_CODE_4__ - Merge multiple parse results
- __INLINE_CODE_5__ - Split paragraphs into statements
Core Parsing:
- __INLINE_CODE_6__ - Core parser with dot notation support
- __INLINE_CODE_7__ - Try multiple patterns + create parser factory
Runtime Pattern Parsing:
- __INLINE_CODE_8__ - Parse patterns from strings/JSON config (includes parsePattern and parsePatterns)
Flat Group Parsing:
- __INLINE_CODE_9__ - Parse with flat groups (no nesting)
- __INLINE_CODE_10__ - Parse multiple statements with flat groups
Nested Statement Parsing:
- __INLINE_CODE_11__ - Parse multiple statements with nested groups
Template Tags:
- __INLINE_CODE_12__ - Template tag API (rx, rxPattern, rxParser)
Buildless Environment Example
<script type="module">
// Only loads split-statements.js (~1KB) instead of full library (~15KB)
import { splitStatements } from './node_modules/nested-regex-groups/split-statements.js';
const statements = splitStatements('First. Second. Third.');
console.log(statements); // ['First', 'Second', 'Third']
</script>
Quick Start
JSON Config (Recommended for Runtime)
Perfect for configuration-driven applications:
import { parsePatterns } from 'nested-regex-groups';
// Load from JSON file
const config = {
patterns: [
{
name: 'email',
pattern: '^(?<user.name>\\w+)@(?<user.domain>\\w+)
Template Tag (Recommended for Code)
The cleanest way for code-based patterns:
;
const result = parser('John Doe');
if (result.success) {
console.log(result.value);
// { person: { name: { first: 'John', last: 'Doe' } } }
}
Multiple Patterns
import { rxParser, rxPattern } from 'nested-regex-groups/template';
const parser = rxParser([
rxPattern('email')`^(?<user.name>\w+)@(?<user.domain>\w+\.\w+)nested-regex-groups
A lightweight TypeScript library that extends JavaScript's regular expressions with dot notation in capture group names to produce nested object structures.
Why?
Standard regex named capture groups return flat objects:
const match = 'john@example.com'.match(/^(?<name>\w+)@(?<domain>\w+\.\w+)$/);
console.log(match.groups);
// { name: 'john', domain: 'example.com' }
With __INLINE_CODE_0__, use dot notation to create nested structures:
import { rx } from 'nested-regex-groups/template';
const parser = rx`^(?<user.name>\w+)@(?<user.domain>\w+\.\w+)nested-regex-groups
A lightweight TypeScript library that extends JavaScript's regular expressions with dot notation in capture group names to produce nested object structures.
Why?
Standard regex named capture groups return flat objects:
const match = 'john@example.com'.match(/^(?<name>\w+)@(?<domain>\w+\.\w+)$/);
console.log(match.groups);
// { name: 'john', domain: 'example.com' }
With __INLINE_CODE_0__, use dot notation to create nested structures:
;
const result = parser('john@example.com');
console.log(result.value);
// { user: { name: 'john', domain: 'example.com' } }
Installation
npm install nested-regex-groups
Features
- Dot notation in capture group names: __INLINE_CODE_1__ → __INLINE_CODE_2__
- Multiple pattern matching: Try patterns in priority order
- Zero dependencies: Tiny footprint
- Type-safe: Full TypeScript support with type inference
- Fast: Minimal overhead over native regex
- Composable: Build complex parsers from simple patterns
- Tree-shakeable: Import only what you need with modular exports
Modular Imports
The library supports selective imports for optimal bundle size, especially useful in buildless environments:
// Import only what you need
import { splitStatements } from 'nested-regex-groups/split-statements';
import { parsePatterns } from 'nested-regex-groups/parse-patterns';
// Or import everything (backward compatible)
import { splitStatements, parsePatterns } from 'nested-regex-groups';
Available Subpath Exports
Core Utilities:
- __INLINE_CODE_3__ - Convert dot-notation keys to nested objects
- __INLINE_CODE_4__ - Merge multiple parse results
- __INLINE_CODE_5__ - Split paragraphs into statements
Core Parsing:
- __INLINE_CODE_6__ - Core parser with dot notation support
- __INLINE_CODE_7__ - Try multiple patterns + create parser factory
Runtime Pattern Parsing:
- __INLINE_CODE_8__ - Parse patterns from strings/JSON config (includes parsePattern and parsePatterns)
Flat Group Parsing:
- __INLINE_CODE_9__ - Parse with flat groups (no nesting)
- __INLINE_CODE_10__ - Parse multiple statements with flat groups
Nested Statement Parsing:
- __INLINE_CODE_11__ - Parse multiple statements with nested groups
Template Tags:
- __INLINE_CODE_12__ - Template tag API (rx, rxPattern, rxParser)
Buildless Environment Example
<script type="module">
// Only loads split-statements.js (~1KB) instead of full library (~15KB)
import { splitStatements } from './node_modules/nested-regex-groups/split-statements.js';
const statements = splitStatements('First. Second. Third.');
console.log(statements); // ['First', 'Second', 'Third']
</script>
Quick Start
JSON Config (Recommended for Runtime)
Perfect for configuration-driven applications:
import { parsePatterns } from 'nested-regex-groups';
// Load from JSON file
const config = {
patterns: [
{
name: 'email',
pattern: '^(?<user.name>\\w+)@(?<user.domain>\\w+)
Template Tag (Recommended for Code)
The cleanest way for code-based patterns:
import { rx } from 'nested-regex-groups/template';
const parser = rx`^(?<person.name.first>\w+)\s+(?<person.name.last>\w+)nested-regex-groups
A lightweight TypeScript library that extends JavaScript's regular expressions with dot notation in capture group names to produce nested object structures.
Why?
Standard regex named capture groups return flat objects:
const match = 'john@example.com'.match(/^(?<name>\w+)@(?<domain>\w+\.\w+)$/);
console.log(match.groups);
// { name: 'john', domain: 'example.com' }
With __INLINE_CODE_0__, use dot notation to create nested structures:
import { rx } from 'nested-regex-groups/template';
const parser = rx`^(?<user.name>\w+)@(?<user.domain>\w+\.\w+)nested-regex-groups
A lightweight TypeScript library that extends JavaScript's regular expressions with dot notation in capture group names to produce nested object structures.
Why?
Standard regex named capture groups return flat objects:
const match = 'john@example.com'.match(/^(?<name>\w+)@(?<domain>\w+\.\w+)$/);
console.log(match.groups);
// { name: 'john', domain: 'example.com' }
With __INLINE_CODE_0__, use dot notation to create nested structures:
;
const result = parser('john@example.com');
console.log(result.value);
// { user: { name: 'john', domain: 'example.com' } }
Installation
npm install nested-regex-groups
Features
- Dot notation in capture group names: __INLINE_CODE_1__ → __INLINE_CODE_2__
- Multiple pattern matching: Try patterns in priority order
- Zero dependencies: Tiny footprint
- Type-safe: Full TypeScript support with type inference
- Fast: Minimal overhead over native regex
- Composable: Build complex parsers from simple patterns
- Tree-shakeable: Import only what you need with modular exports
Modular Imports
The library supports selective imports for optimal bundle size, especially useful in buildless environments:
// Import only what you need
import { splitStatements } from 'nested-regex-groups/split-statements';
import { parsePatterns } from 'nested-regex-groups/parse-patterns';
// Or import everything (backward compatible)
import { splitStatements, parsePatterns } from 'nested-regex-groups';
Available Subpath Exports
Core Utilities:
- __INLINE_CODE_3__ - Convert dot-notation keys to nested objects
- __INLINE_CODE_4__ - Merge multiple parse results
- __INLINE_CODE_5__ - Split paragraphs into statements
Core Parsing:
- __INLINE_CODE_6__ - Core parser with dot notation support
- __INLINE_CODE_7__ - Try multiple patterns + create parser factory
Runtime Pattern Parsing:
- __INLINE_CODE_8__ - Parse patterns from strings/JSON config (includes parsePattern and parsePatterns)
Flat Group Parsing:
- __INLINE_CODE_9__ - Parse with flat groups (no nesting)
- __INLINE_CODE_10__ - Parse multiple statements with flat groups
Nested Statement Parsing:
- __INLINE_CODE_11__ - Parse multiple statements with nested groups
Template Tags:
- __INLINE_CODE_12__ - Template tag API (rx, rxPattern, rxParser)
Buildless Environment Example
<script type="module">
// Only loads split-statements.js (~1KB) instead of full library (~15KB)
import { splitStatements } from './node_modules/nested-regex-groups/split-statements.js';
const statements = splitStatements('First. Second. Third.');
console.log(statements); // ['First', 'Second', 'Third']
</script>
Quick Start
JSON Config (Recommended for Runtime)
Perfect for configuration-driven applications:
import { parsePatterns } from 'nested-regex-groups';
// Load from JSON file
const config = {
patterns: [
{
name: 'email',
pattern: '^(?<user.name>\\w+)@(?<user.domain>\\w+)
Template Tag (Recommended for Code)
The cleanest way for code-based patterns:
;
const result = parser('John Doe');
if (result.success) {
console.log(result.value);
// { person: { name: { first: 'John', last: 'Doe' } } }
}
Multiple Patterns
,
rxPattern('username')`^(?<user.name>\w+)nested-regex-groups
A lightweight TypeScript library that extends JavaScript's regular expressions with dot notation in capture group names to produce nested object structures.
Why?
Standard regex named capture groups return flat objects:
const match = 'john@example.com'.match(/^(?<name>\w+)@(?<domain>\w+\.\w+)$/);
console.log(match.groups);
// { name: 'john', domain: 'example.com' }
With __INLINE_CODE_0__, use dot notation to create nested structures:
import { rx } from 'nested-regex-groups/template';
const parser = rx`^(?<user.name>\w+)@(?<user.domain>\w+\.\w+)nested-regex-groups
A lightweight TypeScript library that extends JavaScript's regular expressions with dot notation in capture group names to produce nested object structures.
Why?
Standard regex named capture groups return flat objects:
const match = 'john@example.com'.match(/^(?<name>\w+)@(?<domain>\w+\.\w+)$/);
console.log(match.groups);
// { name: 'john', domain: 'example.com' }
With __INLINE_CODE_0__, use dot notation to create nested structures:
;
const result = parser('john@example.com');
console.log(result.value);
// { user: { name: 'john', domain: 'example.com' } }
Installation
npm install nested-regex-groups
Features
- Dot notation in capture group names: __INLINE_CODE_1__ → __INLINE_CODE_2__
- Multiple pattern matching: Try patterns in priority order
- Zero dependencies: Tiny footprint
- Type-safe: Full TypeScript support with type inference
- Fast: Minimal overhead over native regex
- Composable: Build complex parsers from simple patterns
- Tree-shakeable: Import only what you need with modular exports
Modular Imports
The library supports selective imports for optimal bundle size, especially useful in buildless environments:
// Import only what you need
import { splitStatements } from 'nested-regex-groups/split-statements';
import { parsePatterns } from 'nested-regex-groups/parse-patterns';
// Or import everything (backward compatible)
import { splitStatements, parsePatterns } from 'nested-regex-groups';
Available Subpath Exports
Core Utilities:
- __INLINE_CODE_3__ - Convert dot-notation keys to nested objects
- __INLINE_CODE_4__ - Merge multiple parse results
- __INLINE_CODE_5__ - Split paragraphs into statements
Core Parsing:
- __INLINE_CODE_6__ - Core parser with dot notation support
- __INLINE_CODE_7__ - Try multiple patterns + create parser factory
Runtime Pattern Parsing:
- __INLINE_CODE_8__ - Parse patterns from strings/JSON config (includes parsePattern and parsePatterns)
Flat Group Parsing:
- __INLINE_CODE_9__ - Parse with flat groups (no nesting)
- __INLINE_CODE_10__ - Parse multiple statements with flat groups
Nested Statement Parsing:
- __INLINE_CODE_11__ - Parse multiple statements with nested groups
Template Tags:
- __INLINE_CODE_12__ - Template tag API (rx, rxPattern, rxParser)
Buildless Environment Example
<script type="module">
// Only loads split-statements.js (~1KB) instead of full library (~15KB)
import { splitStatements } from './node_modules/nested-regex-groups/split-statements.js';
const statements = splitStatements('First. Second. Third.');
console.log(statements); // ['First', 'Second', 'Third']
</script>
Quick Start
JSON Config (Recommended for Runtime)
Perfect for configuration-driven applications:
import { parsePatterns } from 'nested-regex-groups';
// Load from JSON file
const config = {
patterns: [
{
name: 'email',
pattern: '^(?<user.name>\\w+)@(?<user.domain>\\w+)
Template Tag (Recommended for Code)
The cleanest way for code-based patterns:
import { rx } from 'nested-regex-groups/template';
const parser = rx`^(?<person.name.first>\w+)\s+(?<person.name.last>\w+)nested-regex-groups
A lightweight TypeScript library that extends JavaScript's regular expressions with dot notation in capture group names to produce nested object structures.
Why?
Standard regex named capture groups return flat objects:
const match = 'john@example.com'.match(/^(?<name>\w+)@(?<domain>\w+\.\w+)$/);
console.log(match.groups);
// { name: 'john', domain: 'example.com' }
With __INLINE_CODE_0__, use dot notation to create nested structures:
import { rx } from 'nested-regex-groups/template';
const parser = rx`^(?<user.name>\w+)@(?<user.domain>\w+\.\w+)nested-regex-groups
A lightweight TypeScript library that extends JavaScript's regular expressions with dot notation in capture group names to produce nested object structures.
Why?
Standard regex named capture groups return flat objects:
const match = 'john@example.com'.match(/^(?<name>\w+)@(?<domain>\w+\.\w+)$/);
console.log(match.groups);
// { name: 'john', domain: 'example.com' }
With __INLINE_CODE_0__, use dot notation to create nested structures:
;
const result = parser('john@example.com');
console.log(result.value);
// { user: { name: 'john', domain: 'example.com' } }
Installation
npm install nested-regex-groups
Features
- Dot notation in capture group names: __INLINE_CODE_1__ → __INLINE_CODE_2__
- Multiple pattern matching: Try patterns in priority order
- Zero dependencies: Tiny footprint
- Type-safe: Full TypeScript support with type inference
- Fast: Minimal overhead over native regex
- Composable: Build complex parsers from simple patterns
- Tree-shakeable: Import only what you need with modular exports
Modular Imports
The library supports selective imports for optimal bundle size, especially useful in buildless environments:
// Import only what you need
import { splitStatements } from 'nested-regex-groups/split-statements';
import { parsePatterns } from 'nested-regex-groups/parse-patterns';
// Or import everything (backward compatible)
import { splitStatements, parsePatterns } from 'nested-regex-groups';
Available Subpath Exports
Core Utilities:
- __INLINE_CODE_3__ - Convert dot-notation keys to nested objects
- __INLINE_CODE_4__ - Merge multiple parse results
- __INLINE_CODE_5__ - Split paragraphs into statements
Core Parsing:
- __INLINE_CODE_6__ - Core parser with dot notation support
- __INLINE_CODE_7__ - Try multiple patterns + create parser factory
Runtime Pattern Parsing:
- __INLINE_CODE_8__ - Parse patterns from strings/JSON config (includes parsePattern and parsePatterns)
Flat Group Parsing:
- __INLINE_CODE_9__ - Parse with flat groups (no nesting)
- __INLINE_CODE_10__ - Parse multiple statements with flat groups
Nested Statement Parsing:
- __INLINE_CODE_11__ - Parse multiple statements with nested groups
Template Tags:
- __INLINE_CODE_12__ - Template tag API (rx, rxPattern, rxParser)
Buildless Environment Example
<script type="module">
// Only loads split-statements.js (~1KB) instead of full library (~15KB)
import { splitStatements } from './node_modules/nested-regex-groups/split-statements.js';
const statements = splitStatements('First. Second. Third.');
console.log(statements); // ['First', 'Second', 'Third']
</script>
Quick Start
JSON Config (Recommended for Runtime)
Perfect for configuration-driven applications:
import { parsePatterns } from 'nested-regex-groups';
// Load from JSON file
const config = {
patterns: [
{
name: 'email',
pattern: '^(?<user.name>\\w+)@(?<user.domain>\\w+)
Template Tag (Recommended for Code)
The cleanest way for code-based patterns:
;
const result = parser('John Doe');
if (result.success) {
console.log(result.value);
// { person: { name: { first: 'John', last: 'Doe' } } }
}
Multiple Patterns
]);
const result1 = parser('john@example.com');
// { success: true, pattern: 'email', value: { user: { name: 'john', domain: 'example.com' } } }
const result2 = parser('john');
// { success: true, pattern: 'username', value: { user: { name: 'john' } } }
API
Statements Parsing (Multiple Statements in Paragraphs)
Parse paragraphs containing multiple statements separated by periods, with support for nested object structures.
__INLINE_CODE_13__
Splits a paragraph into individual statements based on period delimiters.
import { splitStatements } from 'nested-regex-groups';
const statements = splitStatements('First. Second. Third.');
// ['First', 'Second', 'Third']
// Handles optional chaining and escaped periods
splitStatements('Check #obj?.prop. Use file\\.txt.');
// ['Check #obj?.prop', 'Use file.txt']
Rules:
- Splits on __INLINE_CODE_14__ followed by whitespace or end of string
- Ignores __INLINE_CODE_15__ (optional chaining)
- Ignores __INLINE_CODE_16__ (escaped period - becomes __INLINE_CODE_17__ in output)
- Trailing period on last statement is optional
__INLINE_CODE_18__
Parses a single statement using flat group patterns (no dots in group names).
import { parseGroupedCaptures } from 'nested-regex-groups';
const patterns = [
{ name: 'comparison', pattern: '^(?<trigger>on|off)\\s+when\\s+(?<lhs>#\\w+)\\s+eq\\s+(?<rhs>#\\w+)
Use when: You need flat objects without nesting.
__INLINE_CODE_19__
Parses multiple statements with flat group patterns.
import { parseGroupedCaptureStatements } from 'nested-regex-groups';
const patterns = [
{ name: 'comparison', pattern: '^(?<trigger>on|off)\\s+when\\s+(?<lhs>#\\w+)\\s+eq\\s+(?<rhs>#\\w+)
__INLINE_CODE_20__
Parses multiple statements with nested group patterns (dots in group names).
import { parsePatternStatements } from 'nested-regex-groups';
const patterns = [
{ name: 'comparison', pattern: '^(?<trigger>on|off)\\s+when\\s+(?<lhs.id>#\\w+)\\s+eq\\s+(?<rhs.id>#\\w+)
Use when: You need nested objects from multiple statements.
Default Values
Both __INLINE_CODE_21__ and __INLINE_CODE_22__ support default values for optional capture groups. This is useful when you want to provide fallback values for groups that might not match.
import { parsePatternStatements } from 'nested-regex-groups';
const patterns = [
{
name: 'comparison',
pattern: '^(?<trigger>on|off)?\\s*when\\s+(?<lhs.id>#\\w+)\\s+eq\\s+(?<rhs.id>#\\w+)
Key behaviors:
- Default values are applied when optional groups don't match (return __INLINE_CODE_23__)
- Parsed values always override defaults
- For nested patterns, use dot notation in default keys (e.g., __INLINE_CODE_24__)
- For flat patterns, use simple keys (e.g., __INLINE_CODE_25__)
__INLINE_CODE_26__
Convenience alias for __INLINE_CODE_27__ (the most common use case).
import { parseParagraph } from 'nested-regex-groups';
const result = parseParagraph('on when #foo eq #bar. off when #baz.', patterns);
__INLINE_CODE_28__
Return type for statements parsing functions:
interface StatementsResult<T = any> {
success: boolean; // true if all statements parsed successfully
statements: Array<{
pattern?: string; // Name of matched pattern
value?: T; // Parsed value (if successful)
error?: string; // Error message (if failed)
matched?: string; // Matched text
}>;
}
Example: Real-world be-switched paragraph
import { parsePatternStatements } from 'nested-regex-groups';
const patterns = [
{
name: 'fullComparison',
pattern: '^(?<trigger>on|off)\\s+when\\s+(?<lhs.id>#\\w+)(?:::(?<lhs.event>\\w+))?(?:\\?\\.(?<lhs.prop>\\w+))?\\s+(?<op>eq|gt|lt)\\s+(?<rhs.id>#\\w+)(?:::(?<rhs.event>\\w+))?(?:\\?\\.(?<rhs.prop>\\w+))?
See examples/statements-usage.ts for more examples.
Runtime Parsing (Recommended for JSON Config)
__INLINE_CODE_29__
Parses a regex pattern string with dot notation and creates a parser. Perfect for loading patterns from JSON config files.
import { parsePattern } from 'nested-regex-groups';
// From JSON config
const config = { pattern: "^(?<user.name>\\w+)@(?<user.domain>\\w+)$" };
const parser = parsePattern(config.pattern);
const result = parser('john@example.com');
Parameters:
- __INLINE_CODE_30__ - Regex pattern with dots in group names
- __INLINE_CODE_31__ - Optional name for error messages
Use when:
- Loading patterns from JSON files
- Patterns stored as strings in config
- Dynamic pattern loading at runtime
__INLINE_CODE_32__
Creates a multi-pattern parser from JSON-like configuration objects.
import { parsePatterns } from 'nested-regex-groups';
const config = {
patterns: [
{ name: 'email', pattern: "^(?<user.name>\\w+)@(?<user.domain>\\w+)$" },
{ name: 'username', pattern: "^(?<user.name>\\w+)$" }
]
};
const parser = parsePatterns(config.patterns);
Use when:
- Loading multiple patterns from JSON
- Configuration-driven applications
- Patterns need to be updated without code changes
See JSON_CONFIG.md for complete guide.
Template Tag API (Recommended for Code)
__INLINE_CODE_33__
Template tag for creating single-pattern parsers with dot notation.
;
const result = parser('john@example.com');
Benefits:
- Clean syntax with dots directly in the pattern
- Automatically handles
String.raw behavior
- No manual groupMap needed
Use when:
- Patterns are part of your code
- You want type inference and IDE support
- Patterns rarely change
rxPattern
Creates a pattern definition for use with rxParser.
import { rxPattern } from 'nested-regex-groups/template';
const emailPattern = rxPattern('email', 'Email address')`^(?<user.name>\w+)@(?<user.domain>\w+)nested-regex-groups
A lightweight TypeScript library that extends JavaScript's regular expressions with dot notation in capture group names to produce nested object structures.
Why?
Standard regex named capture groups return flat objects:
const match = 'john@example.com'.match(/^(?<name>\w+)@(?<domain>\w+\.\w+)$/);
console.log(match.groups);
// { name: 'john', domain: 'example.com' }
With __INLINE_CODE_0__, use dot notation to create nested structures:
import { rx } from 'nested-regex-groups/template';
const parser = rx`^(?<user.name>\w+)@(?<user.domain>\w+\.\w+)nested-regex-groups
A lightweight TypeScript library that extends JavaScript's regular expressions with dot notation in capture group names to produce nested object structures.
Why?
Standard regex named capture groups return flat objects:
const match = 'john@example.com'.match(/^(?<name>\w+)@(?<domain>\w+\.\w+)$/);
console.log(match.groups);
// { name: 'john', domain: 'example.com' }
With __INLINE_CODE_0__, use dot notation to create nested structures:
;
const result = parser('john@example.com');
console.log(result.value);
// { user: { name: 'john', domain: 'example.com' } }
Installation
npm install nested-regex-groups
Features
- Dot notation in capture group names: __INLINE_CODE_1__ → __INLINE_CODE_2__
- Multiple pattern matching: Try patterns in priority order
- Zero dependencies: Tiny footprint
- Type-safe: Full TypeScript support with type inference
- Fast: Minimal overhead over native regex
- Composable: Build complex parsers from simple patterns
- Tree-shakeable: Import only what you need with modular exports
Modular Imports
The library supports selective imports for optimal bundle size, especially useful in buildless environments:
// Import only what you need
import { splitStatements } from 'nested-regex-groups/split-statements';
import { parsePatterns } from 'nested-regex-groups/parse-patterns';
// Or import everything (backward compatible)
import { splitStatements, parsePatterns } from 'nested-regex-groups';
Available Subpath Exports
Core Utilities:
- __INLINE_CODE_3__ - Convert dot-notation keys to nested objects
- __INLINE_CODE_4__ - Merge multiple parse results
- __INLINE_CODE_5__ - Split paragraphs into statements
Core Parsing:
- __INLINE_CODE_6__ - Core parser with dot notation support
- __INLINE_CODE_7__ - Try multiple patterns + create parser factory
Runtime Pattern Parsing:
- __INLINE_CODE_8__ - Parse patterns from strings/JSON config (includes parsePattern and parsePatterns)
Flat Group Parsing:
- __INLINE_CODE_9__ - Parse with flat groups (no nesting)
- __INLINE_CODE_10__ - Parse multiple statements with flat groups
Nested Statement Parsing:
- __INLINE_CODE_11__ - Parse multiple statements with nested groups
Template Tags:
- __INLINE_CODE_12__ - Template tag API (rx, rxPattern, rxParser)
Buildless Environment Example
<script type="module">
// Only loads split-statements.js (~1KB) instead of full library (~15KB)
import { splitStatements } from './node_modules/nested-regex-groups/split-statements.js';
const statements = splitStatements('First. Second. Third.');
console.log(statements); // ['First', 'Second', 'Third']
</script>
Quick Start
JSON Config (Recommended for Runtime)
Perfect for configuration-driven applications:
import { parsePatterns } from 'nested-regex-groups';
// Load from JSON file
const config = {
patterns: [
{
name: 'email',
pattern: '^(?<user.name>\\w+)@(?<user.domain>\\w+)
Template Tag (Recommended for Code)
The cleanest way for code-based patterns:
import { rx } from 'nested-regex-groups/template';
const parser = rx`^(?<person.name.first>\w+)\s+(?<person.name.last>\w+)nested-regex-groups
A lightweight TypeScript library that extends JavaScript's regular expressions with dot notation in capture group names to produce nested object structures.
Why?
Standard regex named capture groups return flat objects:
const match = 'john@example.com'.match(/^(?<name>\w+)@(?<domain>\w+\.\w+)$/);
console.log(match.groups);
// { name: 'john', domain: 'example.com' }
With __INLINE_CODE_0__, use dot notation to create nested structures:
import { rx } from 'nested-regex-groups/template';
const parser = rx`^(?<user.name>\w+)@(?<user.domain>\w+\.\w+)nested-regex-groups
A lightweight TypeScript library that extends JavaScript's regular expressions with dot notation in capture group names to produce nested object structures.
Why?
Standard regex named capture groups return flat objects:
const match = 'john@example.com'.match(/^(?<name>\w+)@(?<domain>\w+\.\w+)$/);
console.log(match.groups);
// { name: 'john', domain: 'example.com' }
With __INLINE_CODE_0__, use dot notation to create nested structures:
;
const result = parser('john@example.com');
console.log(result.value);
// { user: { name: 'john', domain: 'example.com' } }
Installation
npm install nested-regex-groups
Features
- Dot notation in capture group names: __INLINE_CODE_1__ → __INLINE_CODE_2__
- Multiple pattern matching: Try patterns in priority order
- Zero dependencies: Tiny footprint
- Type-safe: Full TypeScript support with type inference
- Fast: Minimal overhead over native regex
- Composable: Build complex parsers from simple patterns
- Tree-shakeable: Import only what you need with modular exports
Modular Imports
The library supports selective imports for optimal bundle size, especially useful in buildless environments:
// Import only what you need
import { splitStatements } from 'nested-regex-groups/split-statements';
import { parsePatterns } from 'nested-regex-groups/parse-patterns';
// Or import everything (backward compatible)
import { splitStatements, parsePatterns } from 'nested-regex-groups';
Available Subpath Exports
Core Utilities:
- __INLINE_CODE_3__ - Convert dot-notation keys to nested objects
- __INLINE_CODE_4__ - Merge multiple parse results
- __INLINE_CODE_5__ - Split paragraphs into statements
Core Parsing:
- __INLINE_CODE_6__ - Core parser with dot notation support
- __INLINE_CODE_7__ - Try multiple patterns + create parser factory
Runtime Pattern Parsing:
- __INLINE_CODE_8__ - Parse patterns from strings/JSON config (includes parsePattern and parsePatterns)
Flat Group Parsing:
- __INLINE_CODE_9__ - Parse with flat groups (no nesting)
- __INLINE_CODE_10__ - Parse multiple statements with flat groups
Nested Statement Parsing:
- __INLINE_CODE_11__ - Parse multiple statements with nested groups
Template Tags:
- __INLINE_CODE_12__ - Template tag API (rx, rxPattern, rxParser)
Buildless Environment Example
<script type="module">
// Only loads split-statements.js (~1KB) instead of full library (~15KB)
import { splitStatements } from './node_modules/nested-regex-groups/split-statements.js';
const statements = splitStatements('First. Second. Third.');
console.log(statements); // ['First', 'Second', 'Third']
</script>
Quick Start
JSON Config (Recommended for Runtime)
Perfect for configuration-driven applications:
import { parsePatterns } from 'nested-regex-groups';
// Load from JSON file
const config = {
patterns: [
{
name: 'email',
pattern: '^(?<user.name>\\w+)@(?<user.domain>\\w+)
Template Tag (Recommended for Code)
The cleanest way for code-based patterns:
;
const result = parser('John Doe');
if (result.success) {
console.log(result.value);
// { person: { name: { first: 'John', last: 'Doe' } } }
}
Multiple Patterns
import { rxParser, rxPattern } from 'nested-regex-groups/template';
const parser = rxParser([
rxPattern('email')`^(?<user.name>\w+)@(?<user.domain>\w+\.\w+)nested-regex-groups
A lightweight TypeScript library that extends JavaScript's regular expressions with dot notation in capture group names to produce nested object structures.
Why?
Standard regex named capture groups return flat objects:
const match = 'john@example.com'.match(/^(?<name>\w+)@(?<domain>\w+\.\w+)$/);
console.log(match.groups);
// { name: 'john', domain: 'example.com' }
With __INLINE_CODE_0__, use dot notation to create nested structures:
import { rx } from 'nested-regex-groups/template';
const parser = rx`^(?<user.name>\w+)@(?<user.domain>\w+\.\w+)nested-regex-groups
A lightweight TypeScript library that extends JavaScript's regular expressions with dot notation in capture group names to produce nested object structures.
Why?
Standard regex named capture groups return flat objects:
const match = 'john@example.com'.match(/^(?<name>\w+)@(?<domain>\w+\.\w+)$/);
console.log(match.groups);
// { name: 'john', domain: 'example.com' }
With __INLINE_CODE_0__, use dot notation to create nested structures:
;
const result = parser('john@example.com');
console.log(result.value);
// { user: { name: 'john', domain: 'example.com' } }
Installation
npm install nested-regex-groups
Features
- Dot notation in capture group names: __INLINE_CODE_1__ → __INLINE_CODE_2__
- Multiple pattern matching: Try patterns in priority order
- Zero dependencies: Tiny footprint
- Type-safe: Full TypeScript support with type inference
- Fast: Minimal overhead over native regex
- Composable: Build complex parsers from simple patterns
- Tree-shakeable: Import only what you need with modular exports
Modular Imports
The library supports selective imports for optimal bundle size, especially useful in buildless environments:
// Import only what you need
import { splitStatements } from 'nested-regex-groups/split-statements';
import { parsePatterns } from 'nested-regex-groups/parse-patterns';
// Or import everything (backward compatible)
import { splitStatements, parsePatterns } from 'nested-regex-groups';
Available Subpath Exports
Core Utilities:
- __INLINE_CODE_3__ - Convert dot-notation keys to nested objects
- __INLINE_CODE_4__ - Merge multiple parse results
- __INLINE_CODE_5__ - Split paragraphs into statements
Core Parsing:
- __INLINE_CODE_6__ - Core parser with dot notation support
- __INLINE_CODE_7__ - Try multiple patterns + create parser factory
Runtime Pattern Parsing:
- __INLINE_CODE_8__ - Parse patterns from strings/JSON config (includes parsePattern and parsePatterns)
Flat Group Parsing:
- __INLINE_CODE_9__ - Parse with flat groups (no nesting)
- __INLINE_CODE_10__ - Parse multiple statements with flat groups
Nested Statement Parsing:
- __INLINE_CODE_11__ - Parse multiple statements with nested groups
Template Tags:
- __INLINE_CODE_12__ - Template tag API (rx, rxPattern, rxParser)
Buildless Environment Example
<script type="module">
// Only loads split-statements.js (~1KB) instead of full library (~15KB)
import { splitStatements } from './node_modules/nested-regex-groups/split-statements.js';
const statements = splitStatements('First. Second. Third.');
console.log(statements); // ['First', 'Second', 'Third']
</script>
Quick Start
JSON Config (Recommended for Runtime)
Perfect for configuration-driven applications:
import { parsePatterns } from 'nested-regex-groups';
// Load from JSON file
const config = {
patterns: [
{
name: 'email',
pattern: '^(?<user.name>\\w+)@(?<user.domain>\\w+)
Template Tag (Recommended for Code)
The cleanest way for code-based patterns:
import { rx } from 'nested-regex-groups/template';
const parser = rx`^(?<person.name.first>\w+)\s+(?<person.name.last>\w+)nested-regex-groups
A lightweight TypeScript library that extends JavaScript's regular expressions with dot notation in capture group names to produce nested object structures.
Why?
Standard regex named capture groups return flat objects:
const match = 'john@example.com'.match(/^(?<name>\w+)@(?<domain>\w+\.\w+)$/);
console.log(match.groups);
// { name: 'john', domain: 'example.com' }
With __INLINE_CODE_0__, use dot notation to create nested structures:
import { rx } from 'nested-regex-groups/template';
const parser = rx`^(?<user.name>\w+)@(?<user.domain>\w+\.\w+)nested-regex-groups
A lightweight TypeScript library that extends JavaScript's regular expressions with dot notation in capture group names to produce nested object structures.
Why?
Standard regex named capture groups return flat objects:
const match = 'john@example.com'.match(/^(?<name>\w+)@(?<domain>\w+\.\w+)$/);
console.log(match.groups);
// { name: 'john', domain: 'example.com' }
With __INLINE_CODE_0__, use dot notation to create nested structures:
;
const result = parser('john@example.com');
console.log(result.value);
// { user: { name: 'john', domain: 'example.com' } }
Installation
npm install nested-regex-groups
Features
- Dot notation in capture group names: __INLINE_CODE_1__ → __INLINE_CODE_2__
- Multiple pattern matching: Try patterns in priority order
- Zero dependencies: Tiny footprint
- Type-safe: Full TypeScript support with type inference
- Fast: Minimal overhead over native regex
- Composable: Build complex parsers from simple patterns
- Tree-shakeable: Import only what you need with modular exports
Modular Imports
The library supports selective imports for optimal bundle size, especially useful in buildless environments:
// Import only what you need
import { splitStatements } from 'nested-regex-groups/split-statements';
import { parsePatterns } from 'nested-regex-groups/parse-patterns';
// Or import everything (backward compatible)
import { splitStatements, parsePatterns } from 'nested-regex-groups';
Available Subpath Exports
Core Utilities:
- __INLINE_CODE_3__ - Convert dot-notation keys to nested objects
- __INLINE_CODE_4__ - Merge multiple parse results
- __INLINE_CODE_5__ - Split paragraphs into statements
Core Parsing:
- __INLINE_CODE_6__ - Core parser with dot notation support
- __INLINE_CODE_7__ - Try multiple patterns + create parser factory
Runtime Pattern Parsing:
- __INLINE_CODE_8__ - Parse patterns from strings/JSON config (includes parsePattern and parsePatterns)
Flat Group Parsing:
- __INLINE_CODE_9__ - Parse with flat groups (no nesting)
- __INLINE_CODE_10__ - Parse multiple statements with flat groups
Nested Statement Parsing:
- __INLINE_CODE_11__ - Parse multiple statements with nested groups
Template Tags:
- __INLINE_CODE_12__ - Template tag API (rx, rxPattern, rxParser)
Buildless Environment Example
<script type="module">
// Only loads split-statements.js (~1KB) instead of full library (~15KB)
import { splitStatements } from './node_modules/nested-regex-groups/split-statements.js';
const statements = splitStatements('First. Second. Third.');
console.log(statements); // ['First', 'Second', 'Third']
</script>
Quick Start
JSON Config (Recommended for Runtime)
Perfect for configuration-driven applications:
import { parsePatterns } from 'nested-regex-groups';
// Load from JSON file
const config = {
patterns: [
{
name: 'email',
pattern: '^(?<user.name>\\w+)@(?<user.domain>\\w+)
Template Tag (Recommended for Code)
The cleanest way for code-based patterns:
;
const result = parser('John Doe');
if (result.success) {
console.log(result.value);
// { person: { name: { first: 'John', last: 'Doe' } } }
}
Multiple Patterns
,
rxPattern('username')`^(?<user.name>\w+)nested-regex-groups
A lightweight TypeScript library that extends JavaScript's regular expressions with dot notation in capture group names to produce nested object structures.
Why?
Standard regex named capture groups return flat objects:
const match = 'john@example.com'.match(/^(?<name>\w+)@(?<domain>\w+\.\w+)$/);
console.log(match.groups);
// { name: 'john', domain: 'example.com' }
With __INLINE_CODE_0__, use dot notation to create nested structures:
import { rx } from 'nested-regex-groups/template';
const parser = rx`^(?<user.name>\w+)@(?<user.domain>\w+\.\w+)nested-regex-groups
A lightweight TypeScript library that extends JavaScript's regular expressions with dot notation in capture group names to produce nested object structures.
Why?
Standard regex named capture groups return flat objects:
const match = 'john@example.com'.match(/^(?<name>\w+)@(?<domain>\w+\.\w+)$/);
console.log(match.groups);
// { name: 'john', domain: 'example.com' }
With __INLINE_CODE_0__, use dot notation to create nested structures:
;
const result = parser('john@example.com');
console.log(result.value);
// { user: { name: 'john', domain: 'example.com' } }
Installation
npm install nested-regex-groups
Features
- Dot notation in capture group names: __INLINE_CODE_1__ → __INLINE_CODE_2__
- Multiple pattern matching: Try patterns in priority order
- Zero dependencies: Tiny footprint
- Type-safe: Full TypeScript support with type inference
- Fast: Minimal overhead over native regex
- Composable: Build complex parsers from simple patterns
- Tree-shakeable: Import only what you need with modular exports
Modular Imports
The library supports selective imports for optimal bundle size, especially useful in buildless environments:
// Import only what you need
import { splitStatements } from 'nested-regex-groups/split-statements';
import { parsePatterns } from 'nested-regex-groups/parse-patterns';
// Or import everything (backward compatible)
import { splitStatements, parsePatterns } from 'nested-regex-groups';
Available Subpath Exports
Core Utilities:
- __INLINE_CODE_3__ - Convert dot-notation keys to nested objects
- __INLINE_CODE_4__ - Merge multiple parse results
- __INLINE_CODE_5__ - Split paragraphs into statements
Core Parsing:
- __INLINE_CODE_6__ - Core parser with dot notation support
- __INLINE_CODE_7__ - Try multiple patterns + create parser factory
Runtime Pattern Parsing:
- __INLINE_CODE_8__ - Parse patterns from strings/JSON config (includes parsePattern and parsePatterns)
Flat Group Parsing:
- __INLINE_CODE_9__ - Parse with flat groups (no nesting)
- __INLINE_CODE_10__ - Parse multiple statements with flat groups
Nested Statement Parsing:
- __INLINE_CODE_11__ - Parse multiple statements with nested groups
Template Tags:
- __INLINE_CODE_12__ - Template tag API (rx, rxPattern, rxParser)
Buildless Environment Example
<script type="module">
// Only loads split-statements.js (~1KB) instead of full library (~15KB)
import { splitStatements } from './node_modules/nested-regex-groups/split-statements.js';
const statements = splitStatements('First. Second. Third.');
console.log(statements); // ['First', 'Second', 'Third']
</script>
Quick Start
JSON Config (Recommended for Runtime)
Perfect for configuration-driven applications:
import { parsePatterns } from 'nested-regex-groups';
// Load from JSON file
const config = {
patterns: [
{
name: 'email',
pattern: '^(?<user.name>\\w+)@(?<user.domain>\\w+)
Template Tag (Recommended for Code)
The cleanest way for code-based patterns:
import { rx } from 'nested-regex-groups/template';
const parser = rx`^(?<person.name.first>\w+)\s+(?<person.name.last>\w+)nested-regex-groups
A lightweight TypeScript library that extends JavaScript's regular expressions with dot notation in capture group names to produce nested object structures.
Why?
Standard regex named capture groups return flat objects:
const match = 'john@example.com'.match(/^(?<name>\w+)@(?<domain>\w+\.\w+)$/);
console.log(match.groups);
// { name: 'john', domain: 'example.com' }
With __INLINE_CODE_0__, use dot notation to create nested structures:
import { rx } from 'nested-regex-groups/template';
const parser = rx`^(?<user.name>\w+)@(?<user.domain>\w+\.\w+)nested-regex-groups
A lightweight TypeScript library that extends JavaScript's regular expressions with dot notation in capture group names to produce nested object structures.
Why?
Standard regex named capture groups return flat objects:
const match = 'john@example.com'.match(/^(?<name>\w+)@(?<domain>\w+\.\w+)$/);
console.log(match.groups);
// { name: 'john', domain: 'example.com' }
With __INLINE_CODE_0__, use dot notation to create nested structures:
;
const result = parser('john@example.com');
console.log(result.value);
// { user: { name: 'john', domain: 'example.com' } }
Installation
npm install nested-regex-groups
Features
- Dot notation in capture group names: __INLINE_CODE_1__ → __INLINE_CODE_2__
- Multiple pattern matching: Try patterns in priority order
- Zero dependencies: Tiny footprint
- Type-safe: Full TypeScript support with type inference
- Fast: Minimal overhead over native regex
- Composable: Build complex parsers from simple patterns
- Tree-shakeable: Import only what you need with modular exports
Modular Imports
The library supports selective imports for optimal bundle size, especially useful in buildless environments:
// Import only what you need
import { splitStatements } from 'nested-regex-groups/split-statements';
import { parsePatterns } from 'nested-regex-groups/parse-patterns';
// Or import everything (backward compatible)
import { splitStatements, parsePatterns } from 'nested-regex-groups';
Available Subpath Exports
Core Utilities:
- __INLINE_CODE_3__ - Convert dot-notation keys to nested objects
- __INLINE_CODE_4__ - Merge multiple parse results
- __INLINE_CODE_5__ - Split paragraphs into statements
Core Parsing:
- __INLINE_CODE_6__ - Core parser with dot notation support
- __INLINE_CODE_7__ - Try multiple patterns + create parser factory
Runtime Pattern Parsing:
- __INLINE_CODE_8__ - Parse patterns from strings/JSON config (includes parsePattern and parsePatterns)
Flat Group Parsing:
- __INLINE_CODE_9__ - Parse with flat groups (no nesting)
- __INLINE_CODE_10__ - Parse multiple statements with flat groups
Nested Statement Parsing:
- __INLINE_CODE_11__ - Parse multiple statements with nested groups
Template Tags:
- __INLINE_CODE_12__ - Template tag API (rx, rxPattern, rxParser)
Buildless Environment Example
<script type="module">
// Only loads split-statements.js (~1KB) instead of full library (~15KB)
import { splitStatements } from './node_modules/nested-regex-groups/split-statements.js';
const statements = splitStatements('First. Second. Third.');
console.log(statements); // ['First', 'Second', 'Third']
</script>
Quick Start
JSON Config (Recommended for Runtime)
Perfect for configuration-driven applications:
import { parsePatterns } from 'nested-regex-groups';
// Load from JSON file
const config = {
patterns: [
{
name: 'email',
pattern: '^(?<user.name>\\w+)@(?<user.domain>\\w+)
Template Tag (Recommended for Code)
The cleanest way for code-based patterns:
;
const result = parser('John Doe');
if (result.success) {
console.log(result.value);
// { person: { name: { first: 'John', last: 'Doe' } } }
}
Multiple Patterns
]);
const result1 = parser('john@example.com');
// { success: true, pattern: 'email', value: { user: { name: 'john', domain: 'example.com' } } }
const result2 = parser('john');
// { success: true, pattern: 'username', value: { user: { name: 'john' } } }
API
Statements Parsing (Multiple Statements in Paragraphs)
Parse paragraphs containing multiple statements separated by periods, with support for nested object structures.
__INLINE_CODE_13__
Splits a paragraph into individual statements based on period delimiters.
import { splitStatements } from 'nested-regex-groups';
const statements = splitStatements('First. Second. Third.');
// ['First', 'Second', 'Third']
// Handles optional chaining and escaped periods
splitStatements('Check #obj?.prop. Use file\\.txt.');
// ['Check #obj?.prop', 'Use file.txt']
Rules:
- Splits on __INLINE_CODE_14__ followed by whitespace or end of string
- Ignores __INLINE_CODE_15__ (optional chaining)
- Ignores __INLINE_CODE_16__ (escaped period - becomes __INLINE_CODE_17__ in output)
- Trailing period on last statement is optional
__INLINE_CODE_18__
Parses a single statement using flat group patterns (no dots in group names).
import { parseGroupedCaptures } from 'nested-regex-groups';
const patterns = [
{ name: 'comparison', pattern: '^(?<trigger>on|off)\\s+when\\s+(?<lhs>#\\w+)\\s+eq\\s+(?<rhs>#\\w+)
Use when: You need flat objects without nesting.
__INLINE_CODE_19__
Parses multiple statements with flat group patterns.
import { parseGroupedCaptureStatements } from 'nested-regex-groups';
const patterns = [
{ name: 'comparison', pattern: '^(?<trigger>on|off)\\s+when\\s+(?<lhs>#\\w+)\\s+eq\\s+(?<rhs>#\\w+)
__INLINE_CODE_20__
Parses multiple statements with nested group patterns (dots in group names).
import { parsePatternStatements } from 'nested-regex-groups';
const patterns = [
{ name: 'comparison', pattern: '^(?<trigger>on|off)\\s+when\\s+(?<lhs.id>#\\w+)\\s+eq\\s+(?<rhs.id>#\\w+)
Use when: You need nested objects from multiple statements.
Default Values
Both __INLINE_CODE_21__ and __INLINE_CODE_22__ support default values for optional capture groups. This is useful when you want to provide fallback values for groups that might not match.
import { parsePatternStatements } from 'nested-regex-groups';
const patterns = [
{
name: 'comparison',
pattern: '^(?<trigger>on|off)?\\s*when\\s+(?<lhs.id>#\\w+)\\s+eq\\s+(?<rhs.id>#\\w+)
Key behaviors:
- Default values are applied when optional groups don't match (return __INLINE_CODE_23__)
- Parsed values always override defaults
- For nested patterns, use dot notation in default keys (e.g., __INLINE_CODE_24__)
- For flat patterns, use simple keys (e.g., __INLINE_CODE_25__)
__INLINE_CODE_26__
Convenience alias for __INLINE_CODE_27__ (the most common use case).
import { parseParagraph } from 'nested-regex-groups';
const result = parseParagraph('on when #foo eq #bar. off when #baz.', patterns);
__INLINE_CODE_28__
Return type for statements parsing functions:
interface StatementsResult<T = any> {
success: boolean; // true if all statements parsed successfully
statements: Array<{
pattern?: string; // Name of matched pattern
value?: T; // Parsed value (if successful)
error?: string; // Error message (if failed)
matched?: string; // Matched text
}>;
}
Example: Real-world be-switched paragraph
import { parsePatternStatements } from 'nested-regex-groups';
const patterns = [
{
name: 'fullComparison',
pattern: '^(?<trigger>on|off)\\s+when\\s+(?<lhs.id>#\\w+)(?:::(?<lhs.event>\\w+))?(?:\\?\\.(?<lhs.prop>\\w+))?\\s+(?<op>eq|gt|lt)\\s+(?<rhs.id>#\\w+)(?:::(?<rhs.event>\\w+))?(?:\\?\\.(?<rhs.prop>\\w+))?
See examples/statements-usage.ts for more examples.
Runtime Parsing (Recommended for JSON Config)
__INLINE_CODE_29__
Parses a regex pattern string with dot notation and creates a parser. Perfect for loading patterns from JSON config files.
import { parsePattern } from 'nested-regex-groups';
// From JSON config
const config = { pattern: "^(?<user.name>\\w+)@(?<user.domain>\\w+)$" };
const parser = parsePattern(config.pattern);
const result = parser('john@example.com');
Parameters:
- __INLINE_CODE_30__ - Regex pattern with dots in group names
- __INLINE_CODE_31__ - Optional name for error messages
Use when:
- Loading patterns from JSON files
- Patterns stored as strings in config
- Dynamic pattern loading at runtime
__INLINE_CODE_32__
Creates a multi-pattern parser from JSON-like configuration objects.
import { parsePatterns } from 'nested-regex-groups';
const config = {
patterns: [
{ name: 'email', pattern: "^(?<user.name>\\w+)@(?<user.domain>\\w+)$" },
{ name: 'username', pattern: "^(?<user.name>\\w+)$" }
]
};
const parser = parsePatterns(config.patterns);
Use when:
- Loading multiple patterns from JSON
- Configuration-driven applications
- Patterns need to be updated without code changes
See JSON_CONFIG.md for complete guide.
Template Tag API (Recommended for Code)
__INLINE_CODE_33__
Template tag for creating single-pattern parsers with dot notation.
import { rx } from 'nested-regex-groups/template';
const parser = rx`^(?<user.name>\w+)@(?<user.domain>\w+)nested-regex-groups
A lightweight TypeScript library that extends JavaScript's regular expressions with dot notation in capture group names to produce nested object structures.
Why?
Standard regex named capture groups return flat objects:
const match = 'john@example.com'.match(/^(?<name>\w+)@(?<domain>\w+\.\w+)$/);
console.log(match.groups);
// { name: 'john', domain: 'example.com' }
With __INLINE_CODE_0__, use dot notation to create nested structures:
import { rx } from 'nested-regex-groups/template';
const parser = rx`^(?<user.name>\w+)@(?<user.domain>\w+\.\w+)nested-regex-groups
A lightweight TypeScript library that extends JavaScript's regular expressions with dot notation in capture group names to produce nested object structures.
Why?
Standard regex named capture groups return flat objects:
const match = 'john@example.com'.match(/^(?<name>\w+)@(?<domain>\w+\.\w+)$/);
console.log(match.groups);
// { name: 'john', domain: 'example.com' }
With __INLINE_CODE_0__, use dot notation to create nested structures:
;
const result = parser('john@example.com');
console.log(result.value);
// { user: { name: 'john', domain: 'example.com' } }
Installation
npm install nested-regex-groups
Features
- Dot notation in capture group names: __INLINE_CODE_1__ → __INLINE_CODE_2__
- Multiple pattern matching: Try patterns in priority order
- Zero dependencies: Tiny footprint
- Type-safe: Full TypeScript support with type inference
- Fast: Minimal overhead over native regex
- Composable: Build complex parsers from simple patterns
- Tree-shakeable: Import only what you need with modular exports
Modular Imports
The library supports selective imports for optimal bundle size, especially useful in buildless environments:
// Import only what you need
import { splitStatements } from 'nested-regex-groups/split-statements';
import { parsePatterns } from 'nested-regex-groups/parse-patterns';
// Or import everything (backward compatible)
import { splitStatements, parsePatterns } from 'nested-regex-groups';
Available Subpath Exports
Core Utilities:
- __INLINE_CODE_3__ - Convert dot-notation keys to nested objects
- __INLINE_CODE_4__ - Merge multiple parse results
- __INLINE_CODE_5__ - Split paragraphs into statements
Core Parsing:
- __INLINE_CODE_6__ - Core parser with dot notation support
- __INLINE_CODE_7__ - Try multiple patterns + create parser factory
Runtime Pattern Parsing:
- __INLINE_CODE_8__ - Parse patterns from strings/JSON config (includes parsePattern and parsePatterns)
Flat Group Parsing:
- __INLINE_CODE_9__ - Parse with flat groups (no nesting)
- __INLINE_CODE_10__ - Parse multiple statements with flat groups
Nested Statement Parsing:
- __INLINE_CODE_11__ - Parse multiple statements with nested groups
Template Tags:
- __INLINE_CODE_12__ - Template tag API (rx, rxPattern, rxParser)
Buildless Environment Example
<script type="module">
// Only loads split-statements.js (~1KB) instead of full library (~15KB)
import { splitStatements } from './node_modules/nested-regex-groups/split-statements.js';
const statements = splitStatements('First. Second. Third.');
console.log(statements); // ['First', 'Second', 'Third']
</script>
Quick Start
JSON Config (Recommended for Runtime)
Perfect for configuration-driven applications:
import { parsePatterns } from 'nested-regex-groups';
// Load from JSON file
const config = {
patterns: [
{
name: 'email',
pattern: '^(?<user.name>\\w+)@(?<user.domain>\\w+)
Template Tag (Recommended for Code)
The cleanest way for code-based patterns:
import { rx } from 'nested-regex-groups/template';
const parser = rx`^(?<person.name.first>\w+)\s+(?<person.name.last>\w+)nested-regex-groups
A lightweight TypeScript library that extends JavaScript's regular expressions with dot notation in capture group names to produce nested object structures.
Why?
Standard regex named capture groups return flat objects:
const match = 'john@example.com'.match(/^(?<name>\w+)@(?<domain>\w+\.\w+)$/);
console.log(match.groups);
// { name: 'john', domain: 'example.com' }
With __INLINE_CODE_0__, use dot notation to create nested structures:
import { rx } from 'nested-regex-groups/template';
const parser = rx`^(?<user.name>\w+)@(?<user.domain>\w+\.\w+)nested-regex-groups
A lightweight TypeScript library that extends JavaScript's regular expressions with dot notation in capture group names to produce nested object structures.
Why?
Standard regex named capture groups return flat objects:
const match = 'john@example.com'.match(/^(?<name>\w+)@(?<domain>\w+\.\w+)$/);
console.log(match.groups);
// { name: 'john', domain: 'example.com' }
With __INLINE_CODE_0__, use dot notation to create nested structures:
;
const result = parser('john@example.com');
console.log(result.value);
// { user: { name: 'john', domain: 'example.com' } }
Installation
npm install nested-regex-groups
Features
- Dot notation in capture group names: __INLINE_CODE_1__ → __INLINE_CODE_2__
- Multiple pattern matching: Try patterns in priority order
- Zero dependencies: Tiny footprint
- Type-safe: Full TypeScript support with type inference
- Fast: Minimal overhead over native regex
- Composable: Build complex parsers from simple patterns
- Tree-shakeable: Import only what you need with modular exports
Modular Imports
The library supports selective imports for optimal bundle size, especially useful in buildless environments:
// Import only what you need
import { splitStatements } from 'nested-regex-groups/split-statements';
import { parsePatterns } from 'nested-regex-groups/parse-patterns';
// Or import everything (backward compatible)
import { splitStatements, parsePatterns } from 'nested-regex-groups';
Available Subpath Exports
Core Utilities:
- __INLINE_CODE_3__ - Convert dot-notation keys to nested objects
- __INLINE_CODE_4__ - Merge multiple parse results
- __INLINE_CODE_5__ - Split paragraphs into statements
Core Parsing:
- __INLINE_CODE_6__ - Core parser with dot notation support
- __INLINE_CODE_7__ - Try multiple patterns + create parser factory
Runtime Pattern Parsing:
- __INLINE_CODE_8__ - Parse patterns from strings/JSON config (includes parsePattern and parsePatterns)
Flat Group Parsing:
- __INLINE_CODE_9__ - Parse with flat groups (no nesting)
- __INLINE_CODE_10__ - Parse multiple statements with flat groups
Nested Statement Parsing:
- __INLINE_CODE_11__ - Parse multiple statements with nested groups
Template Tags:
- __INLINE_CODE_12__ - Template tag API (rx, rxPattern, rxParser)
Buildless Environment Example
<script type="module">
// Only loads split-statements.js (~1KB) instead of full library (~15KB)
import { splitStatements } from './node_modules/nested-regex-groups/split-statements.js';
const statements = splitStatements('First. Second. Third.');
console.log(statements); // ['First', 'Second', 'Third']
</script>
Quick Start
JSON Config (Recommended for Runtime)
Perfect for configuration-driven applications:
import { parsePatterns } from 'nested-regex-groups';
// Load from JSON file
const config = {
patterns: [
{
name: 'email',
pattern: '^(?<user.name>\\w+)@(?<user.domain>\\w+)
Template Tag (Recommended for Code)
The cleanest way for code-based patterns:
;
const result = parser('John Doe');
if (result.success) {
console.log(result.value);
// { person: { name: { first: 'John', last: 'Doe' } } }
}
Multiple Patterns
import { rxParser, rxPattern } from 'nested-regex-groups/template';
const parser = rxParser([
rxPattern('email')`^(?<user.name>\w+)@(?<user.domain>\w+\.\w+)nested-regex-groups
A lightweight TypeScript library that extends JavaScript's regular expressions with dot notation in capture group names to produce nested object structures.
Why?
Standard regex named capture groups return flat objects:
const match = 'john@example.com'.match(/^(?<name>\w+)@(?<domain>\w+\.\w+)$/);
console.log(match.groups);
// { name: 'john', domain: 'example.com' }
With __INLINE_CODE_0__, use dot notation to create nested structures:
import { rx } from 'nested-regex-groups/template';
const parser = rx`^(?<user.name>\w+)@(?<user.domain>\w+\.\w+)nested-regex-groups
A lightweight TypeScript library that extends JavaScript's regular expressions with dot notation in capture group names to produce nested object structures.
Why?
Standard regex named capture groups return flat objects:
const match = 'john@example.com'.match(/^(?<name>\w+)@(?<domain>\w+\.\w+)$/);
console.log(match.groups);
// { name: 'john', domain: 'example.com' }
With __INLINE_CODE_0__, use dot notation to create nested structures:
;
const result = parser('john@example.com');
console.log(result.value);
// { user: { name: 'john', domain: 'example.com' } }
Installation
npm install nested-regex-groups
Features
- Dot notation in capture group names: __INLINE_CODE_1__ → __INLINE_CODE_2__
- Multiple pattern matching: Try patterns in priority order
- Zero dependencies: Tiny footprint
- Type-safe: Full TypeScript support with type inference
- Fast: Minimal overhead over native regex
- Composable: Build complex parsers from simple patterns
- Tree-shakeable: Import only what you need with modular exports
Modular Imports
The library supports selective imports for optimal bundle size, especially useful in buildless environments:
// Import only what you need
import { splitStatements } from 'nested-regex-groups/split-statements';
import { parsePatterns } from 'nested-regex-groups/parse-patterns';
// Or import everything (backward compatible)
import { splitStatements, parsePatterns } from 'nested-regex-groups';
Available Subpath Exports
Core Utilities:
- __INLINE_CODE_3__ - Convert dot-notation keys to nested objects
- __INLINE_CODE_4__ - Merge multiple parse results
- __INLINE_CODE_5__ - Split paragraphs into statements
Core Parsing:
- __INLINE_CODE_6__ - Core parser with dot notation support
- __INLINE_CODE_7__ - Try multiple patterns + create parser factory
Runtime Pattern Parsing:
- __INLINE_CODE_8__ - Parse patterns from strings/JSON config (includes parsePattern and parsePatterns)
Flat Group Parsing:
- __INLINE_CODE_9__ - Parse with flat groups (no nesting)
- __INLINE_CODE_10__ - Parse multiple statements with flat groups
Nested Statement Parsing:
- __INLINE_CODE_11__ - Parse multiple statements with nested groups
Template Tags:
- __INLINE_CODE_12__ - Template tag API (rx, rxPattern, rxParser)
Buildless Environment Example
<script type="module">
// Only loads split-statements.js (~1KB) instead of full library (~15KB)
import { splitStatements } from './node_modules/nested-regex-groups/split-statements.js';
const statements = splitStatements('First. Second. Third.');
console.log(statements); // ['First', 'Second', 'Third']
</script>
Quick Start
JSON Config (Recommended for Runtime)
Perfect for configuration-driven applications:
import { parsePatterns } from 'nested-regex-groups';
// Load from JSON file
const config = {
patterns: [
{
name: 'email',
pattern: '^(?<user.name>\\w+)@(?<user.domain>\\w+)
Template Tag (Recommended for Code)
The cleanest way for code-based patterns:
import { rx } from 'nested-regex-groups/template';
const parser = rx`^(?<person.name.first>\w+)\s+(?<person.name.last>\w+)nested-regex-groups
A lightweight TypeScript library that extends JavaScript's regular expressions with dot notation in capture group names to produce nested object structures.
Why?
Standard regex named capture groups return flat objects:
const match = 'john@example.com'.match(/^(?<name>\w+)@(?<domain>\w+\.\w+)$/);
console.log(match.groups);
// { name: 'john', domain: 'example.com' }
With __INLINE_CODE_0__, use dot notation to create nested structures:
import { rx } from 'nested-regex-groups/template';
const parser = rx`^(?<user.name>\w+)@(?<user.domain>\w+\.\w+)nested-regex-groups
A lightweight TypeScript library that extends JavaScript's regular expressions with dot notation in capture group names to produce nested object structures.
Why?
Standard regex named capture groups return flat objects:
const match = 'john@example.com'.match(/^(?<name>\w+)@(?<domain>\w+\.\w+)$/);
console.log(match.groups);
// { name: 'john', domain: 'example.com' }
With __INLINE_CODE_0__, use dot notation to create nested structures:
;
const result = parser('john@example.com');
console.log(result.value);
// { user: { name: 'john', domain: 'example.com' } }
Installation
npm install nested-regex-groups
Features
- Dot notation in capture group names: __INLINE_CODE_1__ → __INLINE_CODE_2__
- Multiple pattern matching: Try patterns in priority order
- Zero dependencies: Tiny footprint
- Type-safe: Full TypeScript support with type inference
- Fast: Minimal overhead over native regex
- Composable: Build complex parsers from simple patterns
- Tree-shakeable: Import only what you need with modular exports
Modular Imports
The library supports selective imports for optimal bundle size, especially useful in buildless environments:
// Import only what you need
import { splitStatements } from 'nested-regex-groups/split-statements';
import { parsePatterns } from 'nested-regex-groups/parse-patterns';
// Or import everything (backward compatible)
import { splitStatements, parsePatterns } from 'nested-regex-groups';
Available Subpath Exports
Core Utilities:
- __INLINE_CODE_3__ - Convert dot-notation keys to nested objects
- __INLINE_CODE_4__ - Merge multiple parse results
- __INLINE_CODE_5__ - Split paragraphs into statements
Core Parsing:
- __INLINE_CODE_6__ - Core parser with dot notation support
- __INLINE_CODE_7__ - Try multiple patterns + create parser factory
Runtime Pattern Parsing:
- __INLINE_CODE_8__ - Parse patterns from strings/JSON config (includes parsePattern and parsePatterns)
Flat Group Parsing:
- __INLINE_CODE_9__ - Parse with flat groups (no nesting)
- __INLINE_CODE_10__ - Parse multiple statements with flat groups
Nested Statement Parsing:
- __INLINE_CODE_11__ - Parse multiple statements with nested groups
Template Tags:
- __INLINE_CODE_12__ - Template tag API (rx, rxPattern, rxParser)
Buildless Environment Example
<script type="module">
// Only loads split-statements.js (~1KB) instead of full library (~15KB)
import { splitStatements } from './node_modules/nested-regex-groups/split-statements.js';
const statements = splitStatements('First. Second. Third.');
console.log(statements); // ['First', 'Second', 'Third']
</script>
Quick Start
JSON Config (Recommended for Runtime)
Perfect for configuration-driven applications:
import { parsePatterns } from 'nested-regex-groups';
// Load from JSON file
const config = {
patterns: [
{
name: 'email',
pattern: '^(?<user.name>\\w+)@(?<user.domain>\\w+)
Template Tag (Recommended for Code)
The cleanest way for code-based patterns:
;
const result = parser('John Doe');
if (result.success) {
console.log(result.value);
// { person: { name: { first: 'John', last: 'Doe' } } }
}
Multiple Patterns
,
rxPattern('username')`^(?<user.name>\w+)nested-regex-groups
A lightweight TypeScript library that extends JavaScript's regular expressions with dot notation in capture group names to produce nested object structures.
Why?
Standard regex named capture groups return flat objects:
const match = 'john@example.com'.match(/^(?<name>\w+)@(?<domain>\w+\.\w+)$/);
console.log(match.groups);
// { name: 'john', domain: 'example.com' }
With __INLINE_CODE_0__, use dot notation to create nested structures:
import { rx } from 'nested-regex-groups/template';
const parser = rx`^(?<user.name>\w+)@(?<user.domain>\w+\.\w+)nested-regex-groups
A lightweight TypeScript library that extends JavaScript's regular expressions with dot notation in capture group names to produce nested object structures.
Why?
Standard regex named capture groups return flat objects:
const match = 'john@example.com'.match(/^(?<name>\w+)@(?<domain>\w+\.\w+)$/);
console.log(match.groups);
// { name: 'john', domain: 'example.com' }
With __INLINE_CODE_0__, use dot notation to create nested structures:
;
const result = parser('john@example.com');
console.log(result.value);
// { user: { name: 'john', domain: 'example.com' } }
Installation
npm install nested-regex-groups
Features
- Dot notation in capture group names: __INLINE_CODE_1__ → __INLINE_CODE_2__
- Multiple pattern matching: Try patterns in priority order
- Zero dependencies: Tiny footprint
- Type-safe: Full TypeScript support with type inference
- Fast: Minimal overhead over native regex
- Composable: Build complex parsers from simple patterns
- Tree-shakeable: Import only what you need with modular exports
Modular Imports
The library supports selective imports for optimal bundle size, especially useful in buildless environments:
// Import only what you need
import { splitStatements } from 'nested-regex-groups/split-statements';
import { parsePatterns } from 'nested-regex-groups/parse-patterns';
// Or import everything (backward compatible)
import { splitStatements, parsePatterns } from 'nested-regex-groups';
Available Subpath Exports
Core Utilities:
- __INLINE_CODE_3__ - Convert dot-notation keys to nested objects
- __INLINE_CODE_4__ - Merge multiple parse results
- __INLINE_CODE_5__ - Split paragraphs into statements
Core Parsing:
- __INLINE_CODE_6__ - Core parser with dot notation support
- __INLINE_CODE_7__ - Try multiple patterns + create parser factory
Runtime Pattern Parsing:
- __INLINE_CODE_8__ - Parse patterns from strings/JSON config (includes parsePattern and parsePatterns)
Flat Group Parsing:
- __INLINE_CODE_9__ - Parse with flat groups (no nesting)
- __INLINE_CODE_10__ - Parse multiple statements with flat groups
Nested Statement Parsing:
- __INLINE_CODE_11__ - Parse multiple statements with nested groups
Template Tags:
- __INLINE_CODE_12__ - Template tag API (rx, rxPattern, rxParser)
Buildless Environment Example
<script type="module">
// Only loads split-statements.js (~1KB) instead of full library (~15KB)
import { splitStatements } from './node_modules/nested-regex-groups/split-statements.js';
const statements = splitStatements('First. Second. Third.');
console.log(statements); // ['First', 'Second', 'Third']
</script>
Quick Start
JSON Config (Recommended for Runtime)
Perfect for configuration-driven applications:
import { parsePatterns } from 'nested-regex-groups';
// Load from JSON file
const config = {
patterns: [
{
name: 'email',
pattern: '^(?<user.name>\\w+)@(?<user.domain>\\w+)
Template Tag (Recommended for Code)
The cleanest way for code-based patterns:
import { rx } from 'nested-regex-groups/template';
const parser = rx`^(?<person.name.first>\w+)\s+(?<person.name.last>\w+)nested-regex-groups
A lightweight TypeScript library that extends JavaScript's regular expressions with dot notation in capture group names to produce nested object structures.
Why?
Standard regex named capture groups return flat objects:
const match = 'john@example.com'.match(/^(?<name>\w+)@(?<domain>\w+\.\w+)$/);
console.log(match.groups);
// { name: 'john', domain: 'example.com' }
With __INLINE_CODE_0__, use dot notation to create nested structures:
import { rx } from 'nested-regex-groups/template';
const parser = rx`^(?<user.name>\w+)@(?<user.domain>\w+\.\w+)nested-regex-groups
A lightweight TypeScript library that extends JavaScript's regular expressions with dot notation in capture group names to produce nested object structures.
Why?
Standard regex named capture groups return flat objects:
const match = 'john@example.com'.match(/^(?<name>\w+)@(?<domain>\w+\.\w+)$/);
console.log(match.groups);
// { name: 'john', domain: 'example.com' }
With __INLINE_CODE_0__, use dot notation to create nested structures:
;
const result = parser('john@example.com');
console.log(result.value);
// { user: { name: 'john', domain: 'example.com' } }
Installation
npm install nested-regex-groups
Features
- Dot notation in capture group names: __INLINE_CODE_1__ → __INLINE_CODE_2__
- Multiple pattern matching: Try patterns in priority order
- Zero dependencies: Tiny footprint
- Type-safe: Full TypeScript support with type inference
- Fast: Minimal overhead over native regex
- Composable: Build complex parsers from simple patterns
- Tree-shakeable: Import only what you need with modular exports
Modular Imports
The library supports selective imports for optimal bundle size, especially useful in buildless environments:
// Import only what you need
import { splitStatements } from 'nested-regex-groups/split-statements';
import { parsePatterns } from 'nested-regex-groups/parse-patterns';
// Or import everything (backward compatible)
import { splitStatements, parsePatterns } from 'nested-regex-groups';
Available Subpath Exports
Core Utilities:
- __INLINE_CODE_3__ - Convert dot-notation keys to nested objects
- __INLINE_CODE_4__ - Merge multiple parse results
- __INLINE_CODE_5__ - Split paragraphs into statements
Core Parsing:
- __INLINE_CODE_6__ - Core parser with dot notation support
- __INLINE_CODE_7__ - Try multiple patterns + create parser factory
Runtime Pattern Parsing:
- __INLINE_CODE_8__ - Parse patterns from strings/JSON config (includes parsePattern and parsePatterns)
Flat Group Parsing:
- __INLINE_CODE_9__ - Parse with flat groups (no nesting)
- __INLINE_CODE_10__ - Parse multiple statements with flat groups
Nested Statement Parsing:
- __INLINE_CODE_11__ - Parse multiple statements with nested groups
Template Tags:
- __INLINE_CODE_12__ - Template tag API (rx, rxPattern, rxParser)
Buildless Environment Example
<script type="module">
// Only loads split-statements.js (~1KB) instead of full library (~15KB)
import { splitStatements } from './node_modules/nested-regex-groups/split-statements.js';
const statements = splitStatements('First. Second. Third.');
console.log(statements); // ['First', 'Second', 'Third']
</script>
Quick Start
JSON Config (Recommended for Runtime)
Perfect for configuration-driven applications:
import { parsePatterns } from 'nested-regex-groups';
// Load from JSON file
const config = {
patterns: [
{
name: 'email',
pattern: '^(?<user.name>\\w+)@(?<user.domain>\\w+)
Template Tag (Recommended for Code)
The cleanest way for code-based patterns:
;
const result = parser('John Doe');
if (result.success) {
console.log(result.value);
// { person: { name: { first: 'John', last: 'Doe' } } }
}
Multiple Patterns
]);
const result1 = parser('john@example.com');
// { success: true, pattern: 'email', value: { user: { name: 'john', domain: 'example.com' } } }
const result2 = parser('john');
// { success: true, pattern: 'username', value: { user: { name: 'john' } } }
API
Statements Parsing (Multiple Statements in Paragraphs)
Parse paragraphs containing multiple statements separated by periods, with support for nested object structures.
__INLINE_CODE_13__
Splits a paragraph into individual statements based on period delimiters.
import { splitStatements } from 'nested-regex-groups';
const statements = splitStatements('First. Second. Third.');
// ['First', 'Second', 'Third']
// Handles optional chaining and escaped periods
splitStatements('Check #obj?.prop. Use file\\.txt.');
// ['Check #obj?.prop', 'Use file.txt']
Rules:
- Splits on __INLINE_CODE_14__ followed by whitespace or end of string
- Ignores __INLINE_CODE_15__ (optional chaining)
- Ignores __INLINE_CODE_16__ (escaped period - becomes __INLINE_CODE_17__ in output)
- Trailing period on last statement is optional
__INLINE_CODE_18__
Parses a single statement using flat group patterns (no dots in group names).
import { parseGroupedCaptures } from 'nested-regex-groups';
const patterns = [
{ name: 'comparison', pattern: '^(?<trigger>on|off)\\s+when\\s+(?<lhs>#\\w+)\\s+eq\\s+(?<rhs>#\\w+)
Use when: You need flat objects without nesting.
__INLINE_CODE_19__
Parses multiple statements with flat group patterns.
import { parseGroupedCaptureStatements } from 'nested-regex-groups';
const patterns = [
{ name: 'comparison', pattern: '^(?<trigger>on|off)\\s+when\\s+(?<lhs>#\\w+)\\s+eq\\s+(?<rhs>#\\w+)
__INLINE_CODE_20__
Parses multiple statements with nested group patterns (dots in group names).
import { parsePatternStatements } from 'nested-regex-groups';
const patterns = [
{ name: 'comparison', pattern: '^(?<trigger>on|off)\\s+when\\s+(?<lhs.id>#\\w+)\\s+eq\\s+(?<rhs.id>#\\w+)
Use when: You need nested objects from multiple statements.
Default Values
Both __INLINE_CODE_21__ and __INLINE_CODE_22__ support default values for optional capture groups. This is useful when you want to provide fallback values for groups that might not match.
import { parsePatternStatements } from 'nested-regex-groups';
const patterns = [
{
name: 'comparison',
pattern: '^(?<trigger>on|off)?\\s*when\\s+(?<lhs.id>#\\w+)\\s+eq\\s+(?<rhs.id>#\\w+)
Key behaviors:
- Default values are applied when optional groups don't match (return __INLINE_CODE_23__)
- Parsed values always override defaults
- For nested patterns, use dot notation in default keys (e.g., __INLINE_CODE_24__)
- For flat patterns, use simple keys (e.g., __INLINE_CODE_25__)
__INLINE_CODE_26__
Convenience alias for __INLINE_CODE_27__ (the most common use case).
import { parseParagraph } from 'nested-regex-groups';
const result = parseParagraph('on when #foo eq #bar. off when #baz.', patterns);
__INLINE_CODE_28__
Return type for statements parsing functions:
interface StatementsResult<T = any> {
success: boolean; // true if all statements parsed successfully
statements: Array<{
pattern?: string; // Name of matched pattern
value?: T; // Parsed value (if successful)
error?: string; // Error message (if failed)
matched?: string; // Matched text
}>;
}
Example: Real-world be-switched paragraph
import { parsePatternStatements } from 'nested-regex-groups';
const patterns = [
{
name: 'fullComparison',
pattern: '^(?<trigger>on|off)\\s+when\\s+(?<lhs.id>#\\w+)(?:::(?<lhs.event>\\w+))?(?:\\?\\.(?<lhs.prop>\\w+))?\\s+(?<op>eq|gt|lt)\\s+(?<rhs.id>#\\w+)(?:::(?<rhs.event>\\w+))?(?:\\?\\.(?<rhs.prop>\\w+))?
See examples/statements-usage.ts for more examples.
Runtime Parsing (Recommended for JSON Config)
__INLINE_CODE_29__
Parses a regex pattern string with dot notation and creates a parser. Perfect for loading patterns from JSON config files.
import { parsePattern } from 'nested-regex-groups';
// From JSON config
const config = { pattern: "^(?<user.name>\\w+)@(?<user.domain>\\w+)$" };
const parser = parsePattern(config.pattern);
const result = parser('john@example.com');
Parameters:
- __INLINE_CODE_30__ - Regex pattern with dots in group names
- __INLINE_CODE_31__ - Optional name for error messages
Use when:
- Loading patterns from JSON files
- Patterns stored as strings in config
- Dynamic pattern loading at runtime
__INLINE_CODE_32__
Creates a multi-pattern parser from JSON-like configuration objects.
import { parsePatterns } from 'nested-regex-groups';
const config = {
patterns: [
{ name: 'email', pattern: "^(?<user.name>\\w+)@(?<user.domain>\\w+)$" },
{ name: 'username', pattern: "^(?<user.name>\\w+)$" }
]
};
const parser = parsePatterns(config.patterns);
Use when:
- Loading multiple patterns from JSON
- Configuration-driven applications
- Patterns need to be updated without code changes
See JSON_CONFIG.md for complete guide.
Template Tag API (Recommended for Code)
__INLINE_CODE_33__
Template tag for creating single-pattern parsers with dot notation.
;
const result = parser('john@example.com');
Benefits:
- Clean syntax with dots directly in the pattern
- Automatically handles __INLINE_CODE_34__ behavior
- No manual groupMap needed
Use when:
- Patterns are part of your code
- You want type inference and IDE support
- Patterns rarely change
__INLINE_CODE_35__
Creates a pattern definition for use with __INLINE_CODE_36__.
;
rxParser
Creates a multi-pattern parser from rxPattern definitions.
import { rxParser, rxPattern } from 'nested-regex-groups/template';
const parser = rxParser([
rxPattern('email')`^(?<user.name>\w+)@(?<user.domain>\w+)nested-regex-groups
A lightweight TypeScript library that extends JavaScript's regular expressions with dot notation in capture group names to produce nested object structures.
Why?
Standard regex named capture groups return flat objects:
const match = 'john@example.com'.match(/^(?<name>\w+)@(?<domain>\w+\.\w+)$/);
console.log(match.groups);
// { name: 'john', domain: 'example.com' }
With __INLINE_CODE_0__, use dot notation to create nested structures:
import { rx } from 'nested-regex-groups/template';
const parser = rx`^(?<user.name>\w+)@(?<user.domain>\w+\.\w+)nested-regex-groups
A lightweight TypeScript library that extends JavaScript's regular expressions with dot notation in capture group names to produce nested object structures.
Why?
Standard regex named capture groups return flat objects:
const match = 'john@example.com'.match(/^(?<name>\w+)@(?<domain>\w+\.\w+)$/);
console.log(match.groups);
// { name: 'john', domain: 'example.com' }
With __INLINE_CODE_0__, use dot notation to create nested structures:
;
const result = parser('john@example.com');
console.log(result.value);
// { user: { name: 'john', domain: 'example.com' } }
Installation
npm install nested-regex-groups
Features
- Dot notation in capture group names: __INLINE_CODE_1__ → __INLINE_CODE_2__
- Multiple pattern matching: Try patterns in priority order
- Zero dependencies: Tiny footprint
- Type-safe: Full TypeScript support with type inference
- Fast: Minimal overhead over native regex
- Composable: Build complex parsers from simple patterns
- Tree-shakeable: Import only what you need with modular exports
Modular Imports
The library supports selective imports for optimal bundle size, especially useful in buildless environments:
// Import only what you need
import { splitStatements } from 'nested-regex-groups/split-statements';
import { parsePatterns } from 'nested-regex-groups/parse-patterns';
// Or import everything (backward compatible)
import { splitStatements, parsePatterns } from 'nested-regex-groups';
Available Subpath Exports
Core Utilities:
- __INLINE_CODE_3__ - Convert dot-notation keys to nested objects
- __INLINE_CODE_4__ - Merge multiple parse results
- __INLINE_CODE_5__ - Split paragraphs into statements
Core Parsing:
- __INLINE_CODE_6__ - Core parser with dot notation support
- __INLINE_CODE_7__ - Try multiple patterns + create parser factory
Runtime Pattern Parsing:
- __INLINE_CODE_8__ - Parse patterns from strings/JSON config (includes parsePattern and parsePatterns)
Flat Group Parsing:
- __INLINE_CODE_9__ - Parse with flat groups (no nesting)
- __INLINE_CODE_10__ - Parse multiple statements with flat groups
Nested Statement Parsing:
- __INLINE_CODE_11__ - Parse multiple statements with nested groups
Template Tags:
- __INLINE_CODE_12__ - Template tag API (rx, rxPattern, rxParser)
Buildless Environment Example
<script type="module">
// Only loads split-statements.js (~1KB) instead of full library (~15KB)
import { splitStatements } from './node_modules/nested-regex-groups/split-statements.js';
const statements = splitStatements('First. Second. Third.');
console.log(statements); // ['First', 'Second', 'Third']
</script>
Quick Start
JSON Config (Recommended for Runtime)
Perfect for configuration-driven applications:
import { parsePatterns } from 'nested-regex-groups';
// Load from JSON file
const config = {
patterns: [
{
name: 'email',
pattern: '^(?<user.name>\\w+)@(?<user.domain>\\w+)
Template Tag (Recommended for Code)
The cleanest way for code-based patterns:
import { rx } from 'nested-regex-groups/template';
const parser = rx`^(?<person.name.first>\w+)\s+(?<person.name.last>\w+)nested-regex-groups
A lightweight TypeScript library that extends JavaScript's regular expressions with dot notation in capture group names to produce nested object structures.
Why?
Standard regex named capture groups return flat objects:
const match = 'john@example.com'.match(/^(?<name>\w+)@(?<domain>\w+\.\w+)$/);
console.log(match.groups);
// { name: 'john', domain: 'example.com' }
With __INLINE_CODE_0__, use dot notation to create nested structures:
import { rx } from 'nested-regex-groups/template';
const parser = rx`^(?<user.name>\w+)@(?<user.domain>\w+\.\w+)nested-regex-groups
A lightweight TypeScript library that extends JavaScript's regular expressions with dot notation in capture group names to produce nested object structures.
Why?
Standard regex named capture groups return flat objects:
const match = 'john@example.com'.match(/^(?<name>\w+)@(?<domain>\w+\.\w+)$/);
console.log(match.groups);
// { name: 'john', domain: 'example.com' }
With __INLINE_CODE_0__, use dot notation to create nested structures:
;
const result = parser('john@example.com');
console.log(result.value);
// { user: { name: 'john', domain: 'example.com' } }
Installation
npm install nested-regex-groups
Features
- Dot notation in capture group names: __INLINE_CODE_1__ → __INLINE_CODE_2__
- Multiple pattern matching: Try patterns in priority order
- Zero dependencies: Tiny footprint
- Type-safe: Full TypeScript support with type inference
- Fast: Minimal overhead over native regex
- Composable: Build complex parsers from simple patterns
- Tree-shakeable: Import only what you need with modular exports
Modular Imports
The library supports selective imports for optimal bundle size, especially useful in buildless environments:
// Import only what you need
import { splitStatements } from 'nested-regex-groups/split-statements';
import { parsePatterns } from 'nested-regex-groups/parse-patterns';
// Or import everything (backward compatible)
import { splitStatements, parsePatterns } from 'nested-regex-groups';
Available Subpath Exports
Core Utilities:
- __INLINE_CODE_3__ - Convert dot-notation keys to nested objects
- __INLINE_CODE_4__ - Merge multiple parse results
- __INLINE_CODE_5__ - Split paragraphs into statements
Core Parsing:
- __INLINE_CODE_6__ - Core parser with dot notation support
- __INLINE_CODE_7__ - Try multiple patterns + create parser factory
Runtime Pattern Parsing:
- __INLINE_CODE_8__ - Parse patterns from strings/JSON config (includes parsePattern and parsePatterns)
Flat Group Parsing:
- __INLINE_CODE_9__ - Parse with flat groups (no nesting)
- __INLINE_CODE_10__ - Parse multiple statements with flat groups
Nested Statement Parsing:
- __INLINE_CODE_11__ - Parse multiple statements with nested groups
Template Tags:
- __INLINE_CODE_12__ - Template tag API (rx, rxPattern, rxParser)
Buildless Environment Example
<script type="module">
// Only loads split-statements.js (~1KB) instead of full library (~15KB)
import { splitStatements } from './node_modules/nested-regex-groups/split-statements.js';
const statements = splitStatements('First. Second. Third.');
console.log(statements); // ['First', 'Second', 'Third']
</script>
Quick Start
JSON Config (Recommended for Runtime)
Perfect for configuration-driven applications:
import { parsePatterns } from 'nested-regex-groups';
// Load from JSON file
const config = {
patterns: [
{
name: 'email',
pattern: '^(?<user.name>\\w+)@(?<user.domain>\\w+)
Template Tag (Recommended for Code)
The cleanest way for code-based patterns:
;
const result = parser('John Doe');
if (result.success) {
console.log(result.value);
// { person: { name: { first: 'John', last: 'Doe' } } }
}
Multiple Patterns
import { rxParser, rxPattern } from 'nested-regex-groups/template';
const parser = rxParser([
rxPattern('email')`^(?<user.name>\w+)@(?<user.domain>\w+\.\w+)nested-regex-groups
A lightweight TypeScript library that extends JavaScript's regular expressions with dot notation in capture group names to produce nested object structures.
Why?
Standard regex named capture groups return flat objects:
const match = 'john@example.com'.match(/^(?<name>\w+)@(?<domain>\w+\.\w+)$/);
console.log(match.groups);
// { name: 'john', domain: 'example.com' }
With __INLINE_CODE_0__, use dot notation to create nested structures:
import { rx } from 'nested-regex-groups/template';
const parser = rx`^(?<user.name>\w+)@(?<user.domain>\w+\.\w+)nested-regex-groups
A lightweight TypeScript library that extends JavaScript's regular expressions with dot notation in capture group names to produce nested object structures.
Why?
Standard regex named capture groups return flat objects:
const match = 'john@example.com'.match(/^(?<name>\w+)@(?<domain>\w+\.\w+)$/);
console.log(match.groups);
// { name: 'john', domain: 'example.com' }
With __INLINE_CODE_0__, use dot notation to create nested structures:
;
const result = parser('john@example.com');
console.log(result.value);
// { user: { name: 'john', domain: 'example.com' } }
Installation
npm install nested-regex-groups
Features
- Dot notation in capture group names: __INLINE_CODE_1__ → __INLINE_CODE_2__
- Multiple pattern matching: Try patterns in priority order
- Zero dependencies: Tiny footprint
- Type-safe: Full TypeScript support with type inference
- Fast: Minimal overhead over native regex
- Composable: Build complex parsers from simple patterns
- Tree-shakeable: Import only what you need with modular exports
Modular Imports
The library supports selective imports for optimal bundle size, especially useful in buildless environments:
// Import only what you need
import { splitStatements } from 'nested-regex-groups/split-statements';
import { parsePatterns } from 'nested-regex-groups/parse-patterns';
// Or import everything (backward compatible)
import { splitStatements, parsePatterns } from 'nested-regex-groups';
Available Subpath Exports
Core Utilities:
- __INLINE_CODE_3__ - Convert dot-notation keys to nested objects
- __INLINE_CODE_4__ - Merge multiple parse results
- __INLINE_CODE_5__ - Split paragraphs into statements
Core Parsing:
- __INLINE_CODE_6__ - Core parser with dot notation support
- __INLINE_CODE_7__ - Try multiple patterns + create parser factory
Runtime Pattern Parsing:
- __INLINE_CODE_8__ - Parse patterns from strings/JSON config (includes parsePattern and parsePatterns)
Flat Group Parsing:
- __INLINE_CODE_9__ - Parse with flat groups (no nesting)
- __INLINE_CODE_10__ - Parse multiple statements with flat groups
Nested Statement Parsing:
- __INLINE_CODE_11__ - Parse multiple statements with nested groups
Template Tags:
- __INLINE_CODE_12__ - Template tag API (rx, rxPattern, rxParser)
Buildless Environment Example
<script type="module">
// Only loads split-statements.js (~1KB) instead of full library (~15KB)
import { splitStatements } from './node_modules/nested-regex-groups/split-statements.js';
const statements = splitStatements('First. Second. Third.');
console.log(statements); // ['First', 'Second', 'Third']
</script>
Quick Start
JSON Config (Recommended for Runtime)
Perfect for configuration-driven applications:
import { parsePatterns } from 'nested-regex-groups';
// Load from JSON file
const config = {
patterns: [
{
name: 'email',
pattern: '^(?<user.name>\\w+)@(?<user.domain>\\w+)
Template Tag (Recommended for Code)
The cleanest way for code-based patterns:
import { rx } from 'nested-regex-groups/template';
const parser = rx`^(?<person.name.first>\w+)\s+(?<person.name.last>\w+)nested-regex-groups
A lightweight TypeScript library that extends JavaScript's regular expressions with dot notation in capture group names to produce nested object structures.
Why?
Standard regex named capture groups return flat objects:
const match = 'john@example.com'.match(/^(?<name>\w+)@(?<domain>\w+\.\w+)$/);
console.log(match.groups);
// { name: 'john', domain: 'example.com' }
With __INLINE_CODE_0__, use dot notation to create nested structures:
import { rx } from 'nested-regex-groups/template';
const parser = rx`^(?<user.name>\w+)@(?<user.domain>\w+\.\w+)nested-regex-groups
A lightweight TypeScript library that extends JavaScript's regular expressions with dot notation in capture group names to produce nested object structures.
Why?
Standard regex named capture groups return flat objects:
const match = 'john@example.com'.match(/^(?<name>\w+)@(?<domain>\w+\.\w+)$/);
console.log(match.groups);
// { name: 'john', domain: 'example.com' }
With __INLINE_CODE_0__, use dot notation to create nested structures:
;
const result = parser('john@example.com');
console.log(result.value);
// { user: { name: 'john', domain: 'example.com' } }
Installation
npm install nested-regex-groups
Features
- Dot notation in capture group names: __INLINE_CODE_1__ → __INLINE_CODE_2__
- Multiple pattern matching: Try patterns in priority order
- Zero dependencies: Tiny footprint
- Type-safe: Full TypeScript support with type inference
- Fast: Minimal overhead over native regex
- Composable: Build complex parsers from simple patterns
- Tree-shakeable: Import only what you need with modular exports
Modular Imports
The library supports selective imports for optimal bundle size, especially useful in buildless environments:
// Import only what you need
import { splitStatements } from 'nested-regex-groups/split-statements';
import { parsePatterns } from 'nested-regex-groups/parse-patterns';
// Or import everything (backward compatible)
import { splitStatements, parsePatterns } from 'nested-regex-groups';
Available Subpath Exports
Core Utilities:
- __INLINE_CODE_3__ - Convert dot-notation keys to nested objects
- __INLINE_CODE_4__ - Merge multiple parse results
- __INLINE_CODE_5__ - Split paragraphs into statements
Core Parsing:
- __INLINE_CODE_6__ - Core parser with dot notation support
- __INLINE_CODE_7__ - Try multiple patterns + create parser factory
Runtime Pattern Parsing:
- __INLINE_CODE_8__ - Parse patterns from strings/JSON config (includes parsePattern and parsePatterns)
Flat Group Parsing:
- __INLINE_CODE_9__ - Parse with flat groups (no nesting)
- __INLINE_CODE_10__ - Parse multiple statements with flat groups
Nested Statement Parsing:
- __INLINE_CODE_11__ - Parse multiple statements with nested groups
Template Tags:
- __INLINE_CODE_12__ - Template tag API (rx, rxPattern, rxParser)
Buildless Environment Example
<script type="module">
// Only loads split-statements.js (~1KB) instead of full library (~15KB)
import { splitStatements } from './node_modules/nested-regex-groups/split-statements.js';
const statements = splitStatements('First. Second. Third.');
console.log(statements); // ['First', 'Second', 'Third']
</script>
Quick Start
JSON Config (Recommended for Runtime)
Perfect for configuration-driven applications:
import { parsePatterns } from 'nested-regex-groups';
// Load from JSON file
const config = {
patterns: [
{
name: 'email',
pattern: '^(?<user.name>\\w+)@(?<user.domain>\\w+)
Template Tag (Recommended for Code)
The cleanest way for code-based patterns:
;
const result = parser('John Doe');
if (result.success) {
console.log(result.value);
// { person: { name: { first: 'John', last: 'Doe' } } }
}
Multiple Patterns
,
rxPattern('username')`^(?<user.name>\w+)nested-regex-groups
A lightweight TypeScript library that extends JavaScript's regular expressions with dot notation in capture group names to produce nested object structures.
Why?
Standard regex named capture groups return flat objects:
const match = 'john@example.com'.match(/^(?<name>\w+)@(?<domain>\w+\.\w+)$/);
console.log(match.groups);
// { name: 'john', domain: 'example.com' }
With __INLINE_CODE_0__, use dot notation to create nested structures:
import { rx } from 'nested-regex-groups/template';
const parser = rx`^(?<user.name>\w+)@(?<user.domain>\w+\.\w+)nested-regex-groups
A lightweight TypeScript library that extends JavaScript's regular expressions with dot notation in capture group names to produce nested object structures.
Why?
Standard regex named capture groups return flat objects:
const match = 'john@example.com'.match(/^(?<name>\w+)@(?<domain>\w+\.\w+)$/);
console.log(match.groups);
// { name: 'john', domain: 'example.com' }
With __INLINE_CODE_0__, use dot notation to create nested structures:
;
const result = parser('john@example.com');
console.log(result.value);
// { user: { name: 'john', domain: 'example.com' } }
Installation
npm install nested-regex-groups
Features
- Dot notation in capture group names: __INLINE_CODE_1__ → __INLINE_CODE_2__
- Multiple pattern matching: Try patterns in priority order
- Zero dependencies: Tiny footprint
- Type-safe: Full TypeScript support with type inference
- Fast: Minimal overhead over native regex
- Composable: Build complex parsers from simple patterns
- Tree-shakeable: Import only what you need with modular exports
Modular Imports
The library supports selective imports for optimal bundle size, especially useful in buildless environments:
// Import only what you need
import { splitStatements } from 'nested-regex-groups/split-statements';
import { parsePatterns } from 'nested-regex-groups/parse-patterns';
// Or import everything (backward compatible)
import { splitStatements, parsePatterns } from 'nested-regex-groups';
Available Subpath Exports
Core Utilities:
- __INLINE_CODE_3__ - Convert dot-notation keys to nested objects
- __INLINE_CODE_4__ - Merge multiple parse results
- __INLINE_CODE_5__ - Split paragraphs into statements
Core Parsing:
- __INLINE_CODE_6__ - Core parser with dot notation support
- __INLINE_CODE_7__ - Try multiple patterns + create parser factory
Runtime Pattern Parsing:
- __INLINE_CODE_8__ - Parse patterns from strings/JSON config (includes parsePattern and parsePatterns)
Flat Group Parsing:
- __INLINE_CODE_9__ - Parse with flat groups (no nesting)
- __INLINE_CODE_10__ - Parse multiple statements with flat groups
Nested Statement Parsing:
- __INLINE_CODE_11__ - Parse multiple statements with nested groups
Template Tags:
- __INLINE_CODE_12__ - Template tag API (rx, rxPattern, rxParser)
Buildless Environment Example
<script type="module">
// Only loads split-statements.js (~1KB) instead of full library (~15KB)
import { splitStatements } from './node_modules/nested-regex-groups/split-statements.js';
const statements = splitStatements('First. Second. Third.');
console.log(statements); // ['First', 'Second', 'Third']
</script>
Quick Start
JSON Config (Recommended for Runtime)
Perfect for configuration-driven applications:
import { parsePatterns } from 'nested-regex-groups';
// Load from JSON file
const config = {
patterns: [
{
name: 'email',
pattern: '^(?<user.name>\\w+)@(?<user.domain>\\w+)
Template Tag (Recommended for Code)
The cleanest way for code-based patterns:
import { rx } from 'nested-regex-groups/template';
const parser = rx`^(?<person.name.first>\w+)\s+(?<person.name.last>\w+)nested-regex-groups
A lightweight TypeScript library that extends JavaScript's regular expressions with dot notation in capture group names to produce nested object structures.
Why?
Standard regex named capture groups return flat objects:
const match = 'john@example.com'.match(/^(?<name>\w+)@(?<domain>\w+\.\w+)$/);
console.log(match.groups);
// { name: 'john', domain: 'example.com' }
With __INLINE_CODE_0__, use dot notation to create nested structures:
import { rx } from 'nested-regex-groups/template';
const parser = rx`^(?<user.name>\w+)@(?<user.domain>\w+\.\w+)nested-regex-groups
A lightweight TypeScript library that extends JavaScript's regular expressions with dot notation in capture group names to produce nested object structures.
Why?
Standard regex named capture groups return flat objects:
const match = 'john@example.com'.match(/^(?<name>\w+)@(?<domain>\w+\.\w+)$/);
console.log(match.groups);
// { name: 'john', domain: 'example.com' }
With __INLINE_CODE_0__, use dot notation to create nested structures:
;
const result = parser('john@example.com');
console.log(result.value);
// { user: { name: 'john', domain: 'example.com' } }
Installation
npm install nested-regex-groups
Features
- Dot notation in capture group names: __INLINE_CODE_1__ → __INLINE_CODE_2__
- Multiple pattern matching: Try patterns in priority order
- Zero dependencies: Tiny footprint
- Type-safe: Full TypeScript support with type inference
- Fast: Minimal overhead over native regex
- Composable: Build complex parsers from simple patterns
- Tree-shakeable: Import only what you need with modular exports
Modular Imports
The library supports selective imports for optimal bundle size, especially useful in buildless environments:
// Import only what you need
import { splitStatements } from 'nested-regex-groups/split-statements';
import { parsePatterns } from 'nested-regex-groups/parse-patterns';
// Or import everything (backward compatible)
import { splitStatements, parsePatterns } from 'nested-regex-groups';
Available Subpath Exports
Core Utilities:
- __INLINE_CODE_3__ - Convert dot-notation keys to nested objects
- __INLINE_CODE_4__ - Merge multiple parse results
- __INLINE_CODE_5__ - Split paragraphs into statements
Core Parsing:
- __INLINE_CODE_6__ - Core parser with dot notation support
- __INLINE_CODE_7__ - Try multiple patterns + create parser factory
Runtime Pattern Parsing:
- __INLINE_CODE_8__ - Parse patterns from strings/JSON config (includes parsePattern and parsePatterns)
Flat Group Parsing:
- __INLINE_CODE_9__ - Parse with flat groups (no nesting)
- __INLINE_CODE_10__ - Parse multiple statements with flat groups
Nested Statement Parsing:
- __INLINE_CODE_11__ - Parse multiple statements with nested groups
Template Tags:
- __INLINE_CODE_12__ - Template tag API (rx, rxPattern, rxParser)
Buildless Environment Example
<script type="module">
// Only loads split-statements.js (~1KB) instead of full library (~15KB)
import { splitStatements } from './node_modules/nested-regex-groups/split-statements.js';
const statements = splitStatements('First. Second. Third.');
console.log(statements); // ['First', 'Second', 'Third']
</script>
Quick Start
JSON Config (Recommended for Runtime)
Perfect for configuration-driven applications:
import { parsePatterns } from 'nested-regex-groups';
// Load from JSON file
const config = {
patterns: [
{
name: 'email',
pattern: '^(?<user.name>\\w+)@(?<user.domain>\\w+)
Template Tag (Recommended for Code)
The cleanest way for code-based patterns:
;
const result = parser('John Doe');
if (result.success) {
console.log(result.value);
// { person: { name: { first: 'John', last: 'Doe' } } }
}
Multiple Patterns
]);
const result1 = parser('john@example.com');
// { success: true, pattern: 'email', value: { user: { name: 'john', domain: 'example.com' } } }
const result2 = parser('john');
// { success: true, pattern: 'username', value: { user: { name: 'john' } } }
API
Statements Parsing (Multiple Statements in Paragraphs)
Parse paragraphs containing multiple statements separated by periods, with support for nested object structures.
__INLINE_CODE_13__
Splits a paragraph into individual statements based on period delimiters.
import { splitStatements } from 'nested-regex-groups';
const statements = splitStatements('First. Second. Third.');
// ['First', 'Second', 'Third']
// Handles optional chaining and escaped periods
splitStatements('Check #obj?.prop. Use file\\.txt.');
// ['Check #obj?.prop', 'Use file.txt']
Rules:
- Splits on __INLINE_CODE_14__ followed by whitespace or end of string
- Ignores __INLINE_CODE_15__ (optional chaining)
- Ignores __INLINE_CODE_16__ (escaped period - becomes __INLINE_CODE_17__ in output)
- Trailing period on last statement is optional
__INLINE_CODE_18__
Parses a single statement using flat group patterns (no dots in group names).
import { parseGroupedCaptures } from 'nested-regex-groups';
const patterns = [
{ name: 'comparison', pattern: '^(?<trigger>on|off)\\s+when\\s+(?<lhs>#\\w+)\\s+eq\\s+(?<rhs>#\\w+)
Use when: You need flat objects without nesting.
__INLINE_CODE_19__
Parses multiple statements with flat group patterns.
import { parseGroupedCaptureStatements } from 'nested-regex-groups';
const patterns = [
{ name: 'comparison', pattern: '^(?<trigger>on|off)\\s+when\\s+(?<lhs>#\\w+)\\s+eq\\s+(?<rhs>#\\w+)
__INLINE_CODE_20__
Parses multiple statements with nested group patterns (dots in group names).
import { parsePatternStatements } from 'nested-regex-groups';
const patterns = [
{ name: 'comparison', pattern: '^(?<trigger>on|off)\\s+when\\s+(?<lhs.id>#\\w+)\\s+eq\\s+(?<rhs.id>#\\w+)
Use when: You need nested objects from multiple statements.
Default Values
Both __INLINE_CODE_21__ and __INLINE_CODE_22__ support default values for optional capture groups. This is useful when you want to provide fallback values for groups that might not match.
import { parsePatternStatements } from 'nested-regex-groups';
const patterns = [
{
name: 'comparison',
pattern: '^(?<trigger>on|off)?\\s*when\\s+(?<lhs.id>#\\w+)\\s+eq\\s+(?<rhs.id>#\\w+)
Key behaviors:
- Default values are applied when optional groups don't match (return __INLINE_CODE_23__)
- Parsed values always override defaults
- For nested patterns, use dot notation in default keys (e.g., __INLINE_CODE_24__)
- For flat patterns, use simple keys (e.g., __INLINE_CODE_25__)
__INLINE_CODE_26__
Convenience alias for __INLINE_CODE_27__ (the most common use case).
import { parseParagraph } from 'nested-regex-groups';
const result = parseParagraph('on when #foo eq #bar. off when #baz.', patterns);
__INLINE_CODE_28__
Return type for statements parsing functions:
interface StatementsResult<T = any> {
success: boolean; // true if all statements parsed successfully
statements: Array<{
pattern?: string; // Name of matched pattern
value?: T; // Parsed value (if successful)
error?: string; // Error message (if failed)
matched?: string; // Matched text
}>;
}
Example: Real-world be-switched paragraph
import { parsePatternStatements } from 'nested-regex-groups';
const patterns = [
{
name: 'fullComparison',
pattern: '^(?<trigger>on|off)\\s+when\\s+(?<lhs.id>#\\w+)(?:::(?<lhs.event>\\w+))?(?:\\?\\.(?<lhs.prop>\\w+))?\\s+(?<op>eq|gt|lt)\\s+(?<rhs.id>#\\w+)(?:::(?<rhs.event>\\w+))?(?:\\?\\.(?<rhs.prop>\\w+))?
See examples/statements-usage.ts for more examples.
Runtime Parsing (Recommended for JSON Config)
__INLINE_CODE_29__
Parses a regex pattern string with dot notation and creates a parser. Perfect for loading patterns from JSON config files.
import { parsePattern } from 'nested-regex-groups';
// From JSON config
const config = { pattern: "^(?<user.name>\\w+)@(?<user.domain>\\w+)$" };
const parser = parsePattern(config.pattern);
const result = parser('john@example.com');
Parameters:
- __INLINE_CODE_30__ - Regex pattern with dots in group names
- __INLINE_CODE_31__ - Optional name for error messages
Use when:
- Loading patterns from JSON files
- Patterns stored as strings in config
- Dynamic pattern loading at runtime
__INLINE_CODE_32__
Creates a multi-pattern parser from JSON-like configuration objects.
import { parsePatterns } from 'nested-regex-groups';
const config = {
patterns: [
{ name: 'email', pattern: "^(?<user.name>\\w+)@(?<user.domain>\\w+)$" },
{ name: 'username', pattern: "^(?<user.name>\\w+)$" }
]
};
const parser = parsePatterns(config.patterns);
Use when:
- Loading multiple patterns from JSON
- Configuration-driven applications
- Patterns need to be updated without code changes
See JSON_CONFIG.md for complete guide.
Template Tag API (Recommended for Code)
__INLINE_CODE_33__
Template tag for creating single-pattern parsers with dot notation.
import { rx } from 'nested-regex-groups/template';
const parser = rx`^(?<user.name>\w+)@(?<user.domain>\w+)nested-regex-groups
A lightweight TypeScript library that extends JavaScript's regular expressions with dot notation in capture group names to produce nested object structures.
Why?
Standard regex named capture groups return flat objects:
const match = 'john@example.com'.match(/^(?<name>\w+)@(?<domain>\w+\.\w+)$/);
console.log(match.groups);
// { name: 'john', domain: 'example.com' }
With __INLINE_CODE_0__, use dot notation to create nested structures:
import { rx } from 'nested-regex-groups/template';
const parser = rx`^(?<user.name>\w+)@(?<user.domain>\w+\.\w+)nested-regex-groups
A lightweight TypeScript library that extends JavaScript's regular expressions with dot notation in capture group names to produce nested object structures.
Why?
Standard regex named capture groups return flat objects:
const match = 'john@example.com'.match(/^(?<name>\w+)@(?<domain>\w+\.\w+)$/);
console.log(match.groups);
// { name: 'john', domain: 'example.com' }
With __INLINE_CODE_0__, use dot notation to create nested structures:
;
const result = parser('john@example.com');
console.log(result.value);
// { user: { name: 'john', domain: 'example.com' } }
Installation
npm install nested-regex-groups
Features
- Dot notation in capture group names: __INLINE_CODE_1__ → __INLINE_CODE_2__
- Multiple pattern matching: Try patterns in priority order
- Zero dependencies: Tiny footprint
- Type-safe: Full TypeScript support with type inference
- Fast: Minimal overhead over native regex
- Composable: Build complex parsers from simple patterns
- Tree-shakeable: Import only what you need with modular exports
Modular Imports
The library supports selective imports for optimal bundle size, especially useful in buildless environments:
// Import only what you need
import { splitStatements } from 'nested-regex-groups/split-statements';
import { parsePatterns } from 'nested-regex-groups/parse-patterns';
// Or import everything (backward compatible)
import { splitStatements, parsePatterns } from 'nested-regex-groups';
Available Subpath Exports
Core Utilities:
- __INLINE_CODE_3__ - Convert dot-notation keys to nested objects
- __INLINE_CODE_4__ - Merge multiple parse results
- __INLINE_CODE_5__ - Split paragraphs into statements
Core Parsing:
- __INLINE_CODE_6__ - Core parser with dot notation support
- __INLINE_CODE_7__ - Try multiple patterns + create parser factory
Runtime Pattern Parsing:
- __INLINE_CODE_8__ - Parse patterns from strings/JSON config (includes parsePattern and parsePatterns)
Flat Group Parsing:
- __INLINE_CODE_9__ - Parse with flat groups (no nesting)
- __INLINE_CODE_10__ - Parse multiple statements with flat groups
Nested Statement Parsing:
- __INLINE_CODE_11__ - Parse multiple statements with nested groups
Template Tags:
- __INLINE_CODE_12__ - Template tag API (rx, rxPattern, rxParser)
Buildless Environment Example
<script type="module">
// Only loads split-statements.js (~1KB) instead of full library (~15KB)
import { splitStatements } from './node_modules/nested-regex-groups/split-statements.js';
const statements = splitStatements('First. Second. Third.');
console.log(statements); // ['First', 'Second', 'Third']
</script>
Quick Start
JSON Config (Recommended for Runtime)
Perfect for configuration-driven applications:
import { parsePatterns } from 'nested-regex-groups';
// Load from JSON file
const config = {
patterns: [
{
name: 'email',
pattern: '^(?<user.name>\\w+)@(?<user.domain>\\w+)
Template Tag (Recommended for Code)
The cleanest way for code-based patterns:
import { rx } from 'nested-regex-groups/template';
const parser = rx`^(?<person.name.first>\w+)\s+(?<person.name.last>\w+)nested-regex-groups
A lightweight TypeScript library that extends JavaScript's regular expressions with dot notation in capture group names to produce nested object structures.
Why?
Standard regex named capture groups return flat objects:
const match = 'john@example.com'.match(/^(?<name>\w+)@(?<domain>\w+\.\w+)$/);
console.log(match.groups);
// { name: 'john', domain: 'example.com' }
With __INLINE_CODE_0__, use dot notation to create nested structures:
import { rx } from 'nested-regex-groups/template';
const parser = rx`^(?<user.name>\w+)@(?<user.domain>\w+\.\w+)nested-regex-groups
A lightweight TypeScript library that extends JavaScript's regular expressions with dot notation in capture group names to produce nested object structures.
Why?
Standard regex named capture groups return flat objects:
const match = 'john@example.com'.match(/^(?<name>\w+)@(?<domain>\w+\.\w+)$/);
console.log(match.groups);
// { name: 'john', domain: 'example.com' }
With __INLINE_CODE_0__, use dot notation to create nested structures:
;
const result = parser('john@example.com');
console.log(result.value);
// { user: { name: 'john', domain: 'example.com' } }
Installation
npm install nested-regex-groups
Features
- Dot notation in capture group names: __INLINE_CODE_1__ → __INLINE_CODE_2__
- Multiple pattern matching: Try patterns in priority order
- Zero dependencies: Tiny footprint
- Type-safe: Full TypeScript support with type inference
- Fast: Minimal overhead over native regex
- Composable: Build complex parsers from simple patterns
- Tree-shakeable: Import only what you need with modular exports
Modular Imports
The library supports selective imports for optimal bundle size, especially useful in buildless environments:
// Import only what you need
import { splitStatements } from 'nested-regex-groups/split-statements';
import { parsePatterns } from 'nested-regex-groups/parse-patterns';
// Or import everything (backward compatible)
import { splitStatements, parsePatterns } from 'nested-regex-groups';
Available Subpath Exports
Core Utilities:
- __INLINE_CODE_3__ - Convert dot-notation keys to nested objects
- __INLINE_CODE_4__ - Merge multiple parse results
- __INLINE_CODE_5__ - Split paragraphs into statements
Core Parsing:
- __INLINE_CODE_6__ - Core parser with dot notation support
- __INLINE_CODE_7__ - Try multiple patterns + create parser factory
Runtime Pattern Parsing:
- __INLINE_CODE_8__ - Parse patterns from strings/JSON config (includes parsePattern and parsePatterns)
Flat Group Parsing:
- __INLINE_CODE_9__ - Parse with flat groups (no nesting)
- __INLINE_CODE_10__ - Parse multiple statements with flat groups
Nested Statement Parsing:
- __INLINE_CODE_11__ - Parse multiple statements with nested groups
Template Tags:
- __INLINE_CODE_12__ - Template tag API (rx, rxPattern, rxParser)
Buildless Environment Example
<script type="module">
// Only loads split-statements.js (~1KB) instead of full library (~15KB)
import { splitStatements } from './node_modules/nested-regex-groups/split-statements.js';
const statements = splitStatements('First. Second. Third.');
console.log(statements); // ['First', 'Second', 'Third']
</script>
Quick Start
JSON Config (Recommended for Runtime)
Perfect for configuration-driven applications:
import { parsePatterns } from 'nested-regex-groups';
// Load from JSON file
const config = {
patterns: [
{
name: 'email',
pattern: '^(?<user.name>\\w+)@(?<user.domain>\\w+)
Template Tag (Recommended for Code)
The cleanest way for code-based patterns:
;
const result = parser('John Doe');
if (result.success) {
console.log(result.value);
// { person: { name: { first: 'John', last: 'Doe' } } }
}
Multiple Patterns
import { rxParser, rxPattern } from 'nested-regex-groups/template';
const parser = rxParser([
rxPattern('email')`^(?<user.name>\w+)@(?<user.domain>\w+\.\w+)nested-regex-groups
A lightweight TypeScript library that extends JavaScript's regular expressions with dot notation in capture group names to produce nested object structures.
Why?
Standard regex named capture groups return flat objects:
const match = 'john@example.com'.match(/^(?<name>\w+)@(?<domain>\w+\.\w+)$/);
console.log(match.groups);
// { name: 'john', domain: 'example.com' }
With __INLINE_CODE_0__, use dot notation to create nested structures:
import { rx } from 'nested-regex-groups/template';
const parser = rx`^(?<user.name>\w+)@(?<user.domain>\w+\.\w+)nested-regex-groups
A lightweight TypeScript library that extends JavaScript's regular expressions with dot notation in capture group names to produce nested object structures.
Why?
Standard regex named capture groups return flat objects:
const match = 'john@example.com'.match(/^(?<name>\w+)@(?<domain>\w+\.\w+)$/);
console.log(match.groups);
// { name: 'john', domain: 'example.com' }
With __INLINE_CODE_0__, use dot notation to create nested structures:
;
const result = parser('john@example.com');
console.log(result.value);
// { user: { name: 'john', domain: 'example.com' } }
Installation
npm install nested-regex-groups
Features
- Dot notation in capture group names: __INLINE_CODE_1__ → __INLINE_CODE_2__
- Multiple pattern matching: Try patterns in priority order
- Zero dependencies: Tiny footprint
- Type-safe: Full TypeScript support with type inference
- Fast: Minimal overhead over native regex
- Composable: Build complex parsers from simple patterns
- Tree-shakeable: Import only what you need with modular exports
Modular Imports
The library supports selective imports for optimal bundle size, especially useful in buildless environments:
// Import only what you need
import { splitStatements } from 'nested-regex-groups/split-statements';
import { parsePatterns } from 'nested-regex-groups/parse-patterns';
// Or import everything (backward compatible)
import { splitStatements, parsePatterns } from 'nested-regex-groups';
Available Subpath Exports
Core Utilities:
- __INLINE_CODE_3__ - Convert dot-notation keys to nested objects
- __INLINE_CODE_4__ - Merge multiple parse results
- __INLINE_CODE_5__ - Split paragraphs into statements
Core Parsing:
- __INLINE_CODE_6__ - Core parser with dot notation support
- __INLINE_CODE_7__ - Try multiple patterns + create parser factory
Runtime Pattern Parsing:
- __INLINE_CODE_8__ - Parse patterns from strings/JSON config (includes parsePattern and parsePatterns)
Flat Group Parsing:
- __INLINE_CODE_9__ - Parse with flat groups (no nesting)
- __INLINE_CODE_10__ - Parse multiple statements with flat groups
Nested Statement Parsing:
- __INLINE_CODE_11__ - Parse multiple statements with nested groups
Template Tags:
- __INLINE_CODE_12__ - Template tag API (rx, rxPattern, rxParser)
Buildless Environment Example
<script type="module">
// Only loads split-statements.js (~1KB) instead of full library (~15KB)
import { splitStatements } from './node_modules/nested-regex-groups/split-statements.js';
const statements = splitStatements('First. Second. Third.');
console.log(statements); // ['First', 'Second', 'Third']
</script>
Quick Start
JSON Config (Recommended for Runtime)
Perfect for configuration-driven applications:
import { parsePatterns } from 'nested-regex-groups';
// Load from JSON file
const config = {
patterns: [
{
name: 'email',
pattern: '^(?<user.name>\\w+)@(?<user.domain>\\w+)
Template Tag (Recommended for Code)
The cleanest way for code-based patterns:
import { rx } from 'nested-regex-groups/template';
const parser = rx`^(?<person.name.first>\w+)\s+(?<person.name.last>\w+)nested-regex-groups
A lightweight TypeScript library that extends JavaScript's regular expressions with dot notation in capture group names to produce nested object structures.
Why?
Standard regex named capture groups return flat objects:
const match = 'john@example.com'.match(/^(?<name>\w+)@(?<domain>\w+\.\w+)$/);
console.log(match.groups);
// { name: 'john', domain: 'example.com' }
With __INLINE_CODE_0__, use dot notation to create nested structures:
import { rx } from 'nested-regex-groups/template';
const parser = rx`^(?<user.name>\w+)@(?<user.domain>\w+\.\w+)nested-regex-groups
A lightweight TypeScript library that extends JavaScript's regular expressions with dot notation in capture group names to produce nested object structures.
Why?
Standard regex named capture groups return flat objects:
const match = 'john@example.com'.match(/^(?<name>\w+)@(?<domain>\w+\.\w+)$/);
console.log(match.groups);
// { name: 'john', domain: 'example.com' }
With __INLINE_CODE_0__, use dot notation to create nested structures:
;
const result = parser('john@example.com');
console.log(result.value);
// { user: { name: 'john', domain: 'example.com' } }
Installation
npm install nested-regex-groups
Features
- Dot notation in capture group names: __INLINE_CODE_1__ → __INLINE_CODE_2__
- Multiple pattern matching: Try patterns in priority order
- Zero dependencies: Tiny footprint
- Type-safe: Full TypeScript support with type inference
- Fast: Minimal overhead over native regex
- Composable: Build complex parsers from simple patterns
- Tree-shakeable: Import only what you need with modular exports
Modular Imports
The library supports selective imports for optimal bundle size, especially useful in buildless environments:
// Import only what you need
import { splitStatements } from 'nested-regex-groups/split-statements';
import { parsePatterns } from 'nested-regex-groups/parse-patterns';
// Or import everything (backward compatible)
import { splitStatements, parsePatterns } from 'nested-regex-groups';
Available Subpath Exports
Core Utilities:
- __INLINE_CODE_3__ - Convert dot-notation keys to nested objects
- __INLINE_CODE_4__ - Merge multiple parse results
- __INLINE_CODE_5__ - Split paragraphs into statements
Core Parsing:
- __INLINE_CODE_6__ - Core parser with dot notation support
- __INLINE_CODE_7__ - Try multiple patterns + create parser factory
Runtime Pattern Parsing:
- __INLINE_CODE_8__ - Parse patterns from strings/JSON config (includes parsePattern and parsePatterns)
Flat Group Parsing:
- __INLINE_CODE_9__ - Parse with flat groups (no nesting)
- __INLINE_CODE_10__ - Parse multiple statements with flat groups
Nested Statement Parsing:
- __INLINE_CODE_11__ - Parse multiple statements with nested groups
Template Tags:
- __INLINE_CODE_12__ - Template tag API (rx, rxPattern, rxParser)
Buildless Environment Example
<script type="module">
// Only loads split-statements.js (~1KB) instead of full library (~15KB)
import { splitStatements } from './node_modules/nested-regex-groups/split-statements.js';
const statements = splitStatements('First. Second. Third.');
console.log(statements); // ['First', 'Second', 'Third']
</script>
Quick Start
JSON Config (Recommended for Runtime)
Perfect for configuration-driven applications:
import { parsePatterns } from 'nested-regex-groups';
// Load from JSON file
const config = {
patterns: [
{
name: 'email',
pattern: '^(?<user.name>\\w+)@(?<user.domain>\\w+)
Template Tag (Recommended for Code)
The cleanest way for code-based patterns:
;
const result = parser('John Doe');
if (result.success) {
console.log(result.value);
// { person: { name: { first: 'John', last: 'Doe' } } }
}
Multiple Patterns
,
rxPattern('username')`^(?<user.name>\w+)nested-regex-groups
A lightweight TypeScript library that extends JavaScript's regular expressions with dot notation in capture group names to produce nested object structures.
Why?
Standard regex named capture groups return flat objects:
const match = 'john@example.com'.match(/^(?<name>\w+)@(?<domain>\w+\.\w+)$/);
console.log(match.groups);
// { name: 'john', domain: 'example.com' }
With __INLINE_CODE_0__, use dot notation to create nested structures:
import { rx } from 'nested-regex-groups/template';
const parser = rx`^(?<user.name>\w+)@(?<user.domain>\w+\.\w+)nested-regex-groups
A lightweight TypeScript library that extends JavaScript's regular expressions with dot notation in capture group names to produce nested object structures.
Why?
Standard regex named capture groups return flat objects:
const match = 'john@example.com'.match(/^(?<name>\w+)@(?<domain>\w+\.\w+)$/);
console.log(match.groups);
// { name: 'john', domain: 'example.com' }
With __INLINE_CODE_0__, use dot notation to create nested structures:
;
const result = parser('john@example.com');
console.log(result.value);
// { user: { name: 'john', domain: 'example.com' } }
Installation
npm install nested-regex-groups
Features
- Dot notation in capture group names: __INLINE_CODE_1__ → __INLINE_CODE_2__
- Multiple pattern matching: Try patterns in priority order
- Zero dependencies: Tiny footprint
- Type-safe: Full TypeScript support with type inference
- Fast: Minimal overhead over native regex
- Composable: Build complex parsers from simple patterns
- Tree-shakeable: Import only what you need with modular exports
Modular Imports
The library supports selective imports for optimal bundle size, especially useful in buildless environments:
// Import only what you need
import { splitStatements } from 'nested-regex-groups/split-statements';
import { parsePatterns } from 'nested-regex-groups/parse-patterns';
// Or import everything (backward compatible)
import { splitStatements, parsePatterns } from 'nested-regex-groups';
Available Subpath Exports
Core Utilities:
- __INLINE_CODE_3__ - Convert dot-notation keys to nested objects
- __INLINE_CODE_4__ - Merge multiple parse results
- __INLINE_CODE_5__ - Split paragraphs into statements
Core Parsing:
- __INLINE_CODE_6__ - Core parser with dot notation support
- __INLINE_CODE_7__ - Try multiple patterns + create parser factory
Runtime Pattern Parsing:
- __INLINE_CODE_8__ - Parse patterns from strings/JSON config (includes parsePattern and parsePatterns)
Flat Group Parsing:
- __INLINE_CODE_9__ - Parse with flat groups (no nesting)
- __INLINE_CODE_10__ - Parse multiple statements with flat groups
Nested Statement Parsing:
- __INLINE_CODE_11__ - Parse multiple statements with nested groups
Template Tags:
- __INLINE_CODE_12__ - Template tag API (rx, rxPattern, rxParser)
Buildless Environment Example
<script type="module">
// Only loads split-statements.js (~1KB) instead of full library (~15KB)
import { splitStatements } from './node_modules/nested-regex-groups/split-statements.js';
const statements = splitStatements('First. Second. Third.');
console.log(statements); // ['First', 'Second', 'Third']
</script>
Quick Start
JSON Config (Recommended for Runtime)
Perfect for configuration-driven applications:
import { parsePatterns } from 'nested-regex-groups';
// Load from JSON file
const config = {
patterns: [
{
name: 'email',
pattern: '^(?<user.name>\\w+)@(?<user.domain>\\w+)
Template Tag (Recommended for Code)
The cleanest way for code-based patterns:
import { rx } from 'nested-regex-groups/template';
const parser = rx`^(?<person.name.first>\w+)\s+(?<person.name.last>\w+)nested-regex-groups
A lightweight TypeScript library that extends JavaScript's regular expressions with dot notation in capture group names to produce nested object structures.
Why?
Standard regex named capture groups return flat objects:
const match = 'john@example.com'.match(/^(?<name>\w+)@(?<domain>\w+\.\w+)$/);
console.log(match.groups);
// { name: 'john', domain: 'example.com' }
With __INLINE_CODE_0__, use dot notation to create nested structures:
import { rx } from 'nested-regex-groups/template';
const parser = rx`^(?<user.name>\w+)@(?<user.domain>\w+\.\w+)nested-regex-groups
A lightweight TypeScript library that extends JavaScript's regular expressions with dot notation in capture group names to produce nested object structures.
Why?
Standard regex named capture groups return flat objects:
const match = 'john@example.com'.match(/^(?<name>\w+)@(?<domain>\w+\.\w+)$/);
console.log(match.groups);
// { name: 'john', domain: 'example.com' }
With __INLINE_CODE_0__, use dot notation to create nested structures:
;
const result = parser('john@example.com');
console.log(result.value);
// { user: { name: 'john', domain: 'example.com' } }
Installation
npm install nested-regex-groups
Features
- Dot notation in capture group names: __INLINE_CODE_1__ → __INLINE_CODE_2__
- Multiple pattern matching: Try patterns in priority order
- Zero dependencies: Tiny footprint
- Type-safe: Full TypeScript support with type inference
- Fast: Minimal overhead over native regex
- Composable: Build complex parsers from simple patterns
- Tree-shakeable: Import only what you need with modular exports
Modular Imports
The library supports selective imports for optimal bundle size, especially useful in buildless environments:
// Import only what you need
import { splitStatements } from 'nested-regex-groups/split-statements';
import { parsePatterns } from 'nested-regex-groups/parse-patterns';
// Or import everything (backward compatible)
import { splitStatements, parsePatterns } from 'nested-regex-groups';
Available Subpath Exports
Core Utilities:
- __INLINE_CODE_3__ - Convert dot-notation keys to nested objects
- __INLINE_CODE_4__ - Merge multiple parse results
- __INLINE_CODE_5__ - Split paragraphs into statements
Core Parsing:
- __INLINE_CODE_6__ - Core parser with dot notation support
- __INLINE_CODE_7__ - Try multiple patterns + create parser factory
Runtime Pattern Parsing:
- __INLINE_CODE_8__ - Parse patterns from strings/JSON config (includes parsePattern and parsePatterns)
Flat Group Parsing:
- __INLINE_CODE_9__ - Parse with flat groups (no nesting)
- __INLINE_CODE_10__ - Parse multiple statements with flat groups
Nested Statement Parsing:
- __INLINE_CODE_11__ - Parse multiple statements with nested groups
Template Tags:
- __INLINE_CODE_12__ - Template tag API (rx, rxPattern, rxParser)
Buildless Environment Example
<script type="module">
// Only loads split-statements.js (~1KB) instead of full library (~15KB)
import { splitStatements } from './node_modules/nested-regex-groups/split-statements.js';
const statements = splitStatements('First. Second. Third.');
console.log(statements); // ['First', 'Second', 'Third']
</script>
Quick Start
JSON Config (Recommended for Runtime)
Perfect for configuration-driven applications:
import { parsePatterns } from 'nested-regex-groups';
// Load from JSON file
const config = {
patterns: [
{
name: 'email',
pattern: '^(?<user.name>\\w+)@(?<user.domain>\\w+)
Template Tag (Recommended for Code)
The cleanest way for code-based patterns:
;
const result = parser('John Doe');
if (result.success) {
console.log(result.value);
// { person: { name: { first: 'John', last: 'Doe' } } }
}
Multiple Patterns
]);
const result1 = parser('john@example.com');
// { success: true, pattern: 'email', value: { user: { name: 'john', domain: 'example.com' } } }
const result2 = parser('john');
// { success: true, pattern: 'username', value: { user: { name: 'john' } } }
API
Statements Parsing (Multiple Statements in Paragraphs)
Parse paragraphs containing multiple statements separated by periods, with support for nested object structures.
__INLINE_CODE_13__
Splits a paragraph into individual statements based on period delimiters.
import { splitStatements } from 'nested-regex-groups';
const statements = splitStatements('First. Second. Third.');
// ['First', 'Second', 'Third']
// Handles optional chaining and escaped periods
splitStatements('Check #obj?.prop. Use file\\.txt.');
// ['Check #obj?.prop', 'Use file.txt']
Rules:
- Splits on __INLINE_CODE_14__ followed by whitespace or end of string
- Ignores __INLINE_CODE_15__ (optional chaining)
- Ignores __INLINE_CODE_16__ (escaped period - becomes __INLINE_CODE_17__ in output)
- Trailing period on last statement is optional
__INLINE_CODE_18__
Parses a single statement using flat group patterns (no dots in group names).
import { parseGroupedCaptures } from 'nested-regex-groups';
const patterns = [
{ name: 'comparison', pattern: '^(?<trigger>on|off)\\s+when\\s+(?<lhs>#\\w+)\\s+eq\\s+(?<rhs>#\\w+)
Use when: You need flat objects without nesting.
__INLINE_CODE_19__
Parses multiple statements with flat group patterns.
import { parseGroupedCaptureStatements } from 'nested-regex-groups';
const patterns = [
{ name: 'comparison', pattern: '^(?<trigger>on|off)\\s+when\\s+(?<lhs>#\\w+)\\s+eq\\s+(?<rhs>#\\w+)
__INLINE_CODE_20__
Parses multiple statements with nested group patterns (dots in group names).
import { parsePatternStatements } from 'nested-regex-groups';
const patterns = [
{ name: 'comparison', pattern: '^(?<trigger>on|off)\\s+when\\s+(?<lhs.id>#\\w+)\\s+eq\\s+(?<rhs.id>#\\w+)
Use when: You need nested objects from multiple statements.
Default Values
Both __INLINE_CODE_21__ and __INLINE_CODE_22__ support default values for optional capture groups. This is useful when you want to provide fallback values for groups that might not match.
import { parsePatternStatements } from 'nested-regex-groups';
const patterns = [
{
name: 'comparison',
pattern: '^(?<trigger>on|off)?\\s*when\\s+(?<lhs.id>#\\w+)\\s+eq\\s+(?<rhs.id>#\\w+)
Key behaviors:
- Default values are applied when optional groups don't match (return __INLINE_CODE_23__)
- Parsed values always override defaults
- For nested patterns, use dot notation in default keys (e.g., __INLINE_CODE_24__)
- For flat patterns, use simple keys (e.g., __INLINE_CODE_25__)
__INLINE_CODE_26__
Convenience alias for __INLINE_CODE_27__ (the most common use case).
import { parseParagraph } from 'nested-regex-groups';
const result = parseParagraph('on when #foo eq #bar. off when #baz.', patterns);
__INLINE_CODE_28__
Return type for statements parsing functions:
interface StatementsResult<T = any> {
success: boolean; // true if all statements parsed successfully
statements: Array<{
pattern?: string; // Name of matched pattern
value?: T; // Parsed value (if successful)
error?: string; // Error message (if failed)
matched?: string; // Matched text
}>;
}
Example: Real-world be-switched paragraph
import { parsePatternStatements } from 'nested-regex-groups';
const patterns = [
{
name: 'fullComparison',
pattern: '^(?<trigger>on|off)\\s+when\\s+(?<lhs.id>#\\w+)(?:::(?<lhs.event>\\w+))?(?:\\?\\.(?<lhs.prop>\\w+))?\\s+(?<op>eq|gt|lt)\\s+(?<rhs.id>#\\w+)(?:::(?<rhs.event>\\w+))?(?:\\?\\.(?<rhs.prop>\\w+))?
See examples/statements-usage.ts for more examples.
Runtime Parsing (Recommended for JSON Config)
__INLINE_CODE_29__
Parses a regex pattern string with dot notation and creates a parser. Perfect for loading patterns from JSON config files.
import { parsePattern } from 'nested-regex-groups';
// From JSON config
const config = { pattern: "^(?<user.name>\\w+)@(?<user.domain>\\w+)$" };
const parser = parsePattern(config.pattern);
const result = parser('john@example.com');
Parameters:
- __INLINE_CODE_30__ - Regex pattern with dots in group names
- __INLINE_CODE_31__ - Optional name for error messages
Use when:
- Loading patterns from JSON files
- Patterns stored as strings in config
- Dynamic pattern loading at runtime
__INLINE_CODE_32__
Creates a multi-pattern parser from JSON-like configuration objects.
import { parsePatterns } from 'nested-regex-groups';
const config = {
patterns: [
{ name: 'email', pattern: "^(?<user.name>\\w+)@(?<user.domain>\\w+)$" },
{ name: 'username', pattern: "^(?<user.name>\\w+)$" }
]
};
const parser = parsePatterns(config.patterns);
Use when:
- Loading multiple patterns from JSON
- Configuration-driven applications
- Patterns need to be updated without code changes
See JSON_CONFIG.md for complete guide.
Template Tag API (Recommended for Code)
__INLINE_CODE_33__
Template tag for creating single-pattern parsers with dot notation.
;
const result = parser('john@example.com');
Benefits:
- Clean syntax with dots directly in the pattern
- Automatically handles __INLINE_CODE_34__ behavior
- No manual groupMap needed
Use when:
- Patterns are part of your code
- You want type inference and IDE support
- Patterns rarely change
__INLINE_CODE_35__
Creates a pattern definition for use with __INLINE_CODE_36__.
import { rxPattern } from 'nested-regex-groups/template';
const emailPattern = rxPattern('email', 'Email address')`^(?<user.name>\w+)@(?<user.domain>\w+)nested-regex-groups
A lightweight TypeScript library that extends JavaScript's regular expressions with dot notation in capture group names to produce nested object structures.
Why?
Standard regex named capture groups return flat objects:
const match = 'john@example.com'.match(/^(?<name>\w+)@(?<domain>\w+\.\w+)$/);
console.log(match.groups);
// { name: 'john', domain: 'example.com' }
With __INLINE_CODE_0__, use dot notation to create nested structures:
import { rx } from 'nested-regex-groups/template';
const parser = rx`^(?<user.name>\w+)@(?<user.domain>\w+\.\w+)nested-regex-groups
A lightweight TypeScript library that extends JavaScript's regular expressions with dot notation in capture group names to produce nested object structures.
Why?
Standard regex named capture groups return flat objects:
const match = 'john@example.com'.match(/^(?<name>\w+)@(?<domain>\w+\.\w+)$/);
console.log(match.groups);
// { name: 'john', domain: 'example.com' }
With __INLINE_CODE_0__, use dot notation to create nested structures:
;
const result = parser('john@example.com');
console.log(result.value);
// { user: { name: 'john', domain: 'example.com' } }
Installation
npm install nested-regex-groups
Features
- Dot notation in capture group names: __INLINE_CODE_1__ → __INLINE_CODE_2__
- Multiple pattern matching: Try patterns in priority order
- Zero dependencies: Tiny footprint
- Type-safe: Full TypeScript support with type inference
- Fast: Minimal overhead over native regex
- Composable: Build complex parsers from simple patterns
- Tree-shakeable: Import only what you need with modular exports
Modular Imports
The library supports selective imports for optimal bundle size, especially useful in buildless environments:
// Import only what you need
import { splitStatements } from 'nested-regex-groups/split-statements';
import { parsePatterns } from 'nested-regex-groups/parse-patterns';
// Or import everything (backward compatible)
import { splitStatements, parsePatterns } from 'nested-regex-groups';
Available Subpath Exports
Core Utilities:
- __INLINE_CODE_3__ - Convert dot-notation keys to nested objects
- __INLINE_CODE_4__ - Merge multiple parse results
- __INLINE_CODE_5__ - Split paragraphs into statements
Core Parsing:
- __INLINE_CODE_6__ - Core parser with dot notation support
- __INLINE_CODE_7__ - Try multiple patterns + create parser factory
Runtime Pattern Parsing:
- __INLINE_CODE_8__ - Parse patterns from strings/JSON config (includes parsePattern and parsePatterns)
Flat Group Parsing:
- __INLINE_CODE_9__ - Parse with flat groups (no nesting)
- __INLINE_CODE_10__ - Parse multiple statements with flat groups
Nested Statement Parsing:
- __INLINE_CODE_11__ - Parse multiple statements with nested groups
Template Tags:
- __INLINE_CODE_12__ - Template tag API (rx, rxPattern, rxParser)
Buildless Environment Example
<script type="module">
// Only loads split-statements.js (~1KB) instead of full library (~15KB)
import { splitStatements } from './node_modules/nested-regex-groups/split-statements.js';
const statements = splitStatements('First. Second. Third.');
console.log(statements); // ['First', 'Second', 'Third']
</script>
Quick Start
JSON Config (Recommended for Runtime)
Perfect for configuration-driven applications:
import { parsePatterns } from 'nested-regex-groups';
// Load from JSON file
const config = {
patterns: [
{
name: 'email',
pattern: '^(?<user.name>\\w+)@(?<user.domain>\\w+)
Template Tag (Recommended for Code)
The cleanest way for code-based patterns:
import { rx } from 'nested-regex-groups/template';
const parser = rx`^(?<person.name.first>\w+)\s+(?<person.name.last>\w+)nested-regex-groups
A lightweight TypeScript library that extends JavaScript's regular expressions with dot notation in capture group names to produce nested object structures.
Why?
Standard regex named capture groups return flat objects:
const match = 'john@example.com'.match(/^(?<name>\w+)@(?<domain>\w+\.\w+)$/);
console.log(match.groups);
// { name: 'john', domain: 'example.com' }
With __INLINE_CODE_0__, use dot notation to create nested structures:
import { rx } from 'nested-regex-groups/template';
const parser = rx`^(?<user.name>\w+)@(?<user.domain>\w+\.\w+)nested-regex-groups
A lightweight TypeScript library that extends JavaScript's regular expressions with dot notation in capture group names to produce nested object structures.
Why?
Standard regex named capture groups return flat objects:
const match = 'john@example.com'.match(/^(?<name>\w+)@(?<domain>\w+\.\w+)$/);
console.log(match.groups);
// { name: 'john', domain: 'example.com' }
With __INLINE_CODE_0__, use dot notation to create nested structures:
;
const result = parser('john@example.com');
console.log(result.value);
// { user: { name: 'john', domain: 'example.com' } }
Installation
npm install nested-regex-groups
Features
- Dot notation in capture group names: __INLINE_CODE_1__ → __INLINE_CODE_2__
- Multiple pattern matching: Try patterns in priority order
- Zero dependencies: Tiny footprint
- Type-safe: Full TypeScript support with type inference
- Fast: Minimal overhead over native regex
- Composable: Build complex parsers from simple patterns
- Tree-shakeable: Import only what you need with modular exports
Modular Imports
The library supports selective imports for optimal bundle size, especially useful in buildless environments:
// Import only what you need
import { splitStatements } from 'nested-regex-groups/split-statements';
import { parsePatterns } from 'nested-regex-groups/parse-patterns';
// Or import everything (backward compatible)
import { splitStatements, parsePatterns } from 'nested-regex-groups';
Available Subpath Exports
Core Utilities:
- __INLINE_CODE_3__ - Convert dot-notation keys to nested objects
- __INLINE_CODE_4__ - Merge multiple parse results
- __INLINE_CODE_5__ - Split paragraphs into statements
Core Parsing:
- __INLINE_CODE_6__ - Core parser with dot notation support
- __INLINE_CODE_7__ - Try multiple patterns + create parser factory
Runtime Pattern Parsing:
- __INLINE_CODE_8__ - Parse patterns from strings/JSON config (includes parsePattern and parsePatterns)
Flat Group Parsing:
- __INLINE_CODE_9__ - Parse with flat groups (no nesting)
- __INLINE_CODE_10__ - Parse multiple statements with flat groups
Nested Statement Parsing:
- __INLINE_CODE_11__ - Parse multiple statements with nested groups
Template Tags:
- __INLINE_CODE_12__ - Template tag API (rx, rxPattern, rxParser)
Buildless Environment Example
<script type="module">
// Only loads split-statements.js (~1KB) instead of full library (~15KB)
import { splitStatements } from './node_modules/nested-regex-groups/split-statements.js';
const statements = splitStatements('First. Second. Third.');
console.log(statements); // ['First', 'Second', 'Third']
</script>
Quick Start
JSON Config (Recommended for Runtime)
Perfect for configuration-driven applications:
import { parsePatterns } from 'nested-regex-groups';
// Load from JSON file
const config = {
patterns: [
{
name: 'email',
pattern: '^(?<user.name>\\w+)@(?<user.domain>\\w+)
Template Tag (Recommended for Code)
The cleanest way for code-based patterns:
;
const result = parser('John Doe');
if (result.success) {
console.log(result.value);
// { person: { name: { first: 'John', last: 'Doe' } } }
}
Multiple Patterns
import { rxParser, rxPattern } from 'nested-regex-groups/template';
const parser = rxParser([
rxPattern('email')`^(?<user.name>\w+)@(?<user.domain>\w+\.\w+)nested-regex-groups
A lightweight TypeScript library that extends JavaScript's regular expressions with dot notation in capture group names to produce nested object structures.
Why?
Standard regex named capture groups return flat objects:
const match = 'john@example.com'.match(/^(?<name>\w+)@(?<domain>\w+\.\w+)$/);
console.log(match.groups);
// { name: 'john', domain: 'example.com' }
With __INLINE_CODE_0__, use dot notation to create nested structures:
import { rx } from 'nested-regex-groups/template';
const parser = rx`^(?<user.name>\w+)@(?<user.domain>\w+\.\w+)nested-regex-groups
A lightweight TypeScript library that extends JavaScript's regular expressions with dot notation in capture group names to produce nested object structures.
Why?
Standard regex named capture groups return flat objects:
const match = 'john@example.com'.match(/^(?<name>\w+)@(?<domain>\w+\.\w+)$/);
console.log(match.groups);
// { name: 'john', domain: 'example.com' }
With __INLINE_CODE_0__, use dot notation to create nested structures:
;
const result = parser('john@example.com');
console.log(result.value);
// { user: { name: 'john', domain: 'example.com' } }
Installation
npm install nested-regex-groups
Features
- Dot notation in capture group names: __INLINE_CODE_1__ → __INLINE_CODE_2__
- Multiple pattern matching: Try patterns in priority order
- Zero dependencies: Tiny footprint
- Type-safe: Full TypeScript support with type inference
- Fast: Minimal overhead over native regex
- Composable: Build complex parsers from simple patterns
- Tree-shakeable: Import only what you need with modular exports
Modular Imports
The library supports selective imports for optimal bundle size, especially useful in buildless environments:
// Import only what you need
import { splitStatements } from 'nested-regex-groups/split-statements';
import { parsePatterns } from 'nested-regex-groups/parse-patterns';
// Or import everything (backward compatible)
import { splitStatements, parsePatterns } from 'nested-regex-groups';
Available Subpath Exports
Core Utilities:
- __INLINE_CODE_3__ - Convert dot-notation keys to nested objects
- __INLINE_CODE_4__ - Merge multiple parse results
- __INLINE_CODE_5__ - Split paragraphs into statements
Core Parsing:
- __INLINE_CODE_6__ - Core parser with dot notation support
- __INLINE_CODE_7__ - Try multiple patterns + create parser factory
Runtime Pattern Parsing:
- __INLINE_CODE_8__ - Parse patterns from strings/JSON config (includes parsePattern and parsePatterns)
Flat Group Parsing:
- __INLINE_CODE_9__ - Parse with flat groups (no nesting)
- __INLINE_CODE_10__ - Parse multiple statements with flat groups
Nested Statement Parsing:
- __INLINE_CODE_11__ - Parse multiple statements with nested groups
Template Tags:
- __INLINE_CODE_12__ - Template tag API (rx, rxPattern, rxParser)
Buildless Environment Example
<script type="module">
// Only loads split-statements.js (~1KB) instead of full library (~15KB)
import { splitStatements } from './node_modules/nested-regex-groups/split-statements.js';
const statements = splitStatements('First. Second. Third.');
console.log(statements); // ['First', 'Second', 'Third']
</script>
Quick Start
JSON Config (Recommended for Runtime)
Perfect for configuration-driven applications:
import { parsePatterns } from 'nested-regex-groups';
// Load from JSON file
const config = {
patterns: [
{
name: 'email',
pattern: '^(?<user.name>\\w+)@(?<user.domain>\\w+)
Template Tag (Recommended for Code)
The cleanest way for code-based patterns:
import { rx } from 'nested-regex-groups/template';
const parser = rx`^(?<person.name.first>\w+)\s+(?<person.name.last>\w+)nested-regex-groups
A lightweight TypeScript library that extends JavaScript's regular expressions with dot notation in capture group names to produce nested object structures.
Why?
Standard regex named capture groups return flat objects:
const match = 'john@example.com'.match(/^(?<name>\w+)@(?<domain>\w+\.\w+)$/);
console.log(match.groups);
// { name: 'john', domain: 'example.com' }
With __INLINE_CODE_0__, use dot notation to create nested structures:
import { rx } from 'nested-regex-groups/template';
const parser = rx`^(?<user.name>\w+)@(?<user.domain>\w+\.\w+)nested-regex-groups
A lightweight TypeScript library that extends JavaScript's regular expressions with dot notation in capture group names to produce nested object structures.
Why?
Standard regex named capture groups return flat objects:
const match = 'john@example.com'.match(/^(?<name>\w+)@(?<domain>\w+\.\w+)$/);
console.log(match.groups);
// { name: 'john', domain: 'example.com' }
With __INLINE_CODE_0__, use dot notation to create nested structures:
;
const result = parser('john@example.com');
console.log(result.value);
// { user: { name: 'john', domain: 'example.com' } }
Installation
npm install nested-regex-groups
Features
- Dot notation in capture group names: __INLINE_CODE_1__ → __INLINE_CODE_2__
- Multiple pattern matching: Try patterns in priority order
- Zero dependencies: Tiny footprint
- Type-safe: Full TypeScript support with type inference
- Fast: Minimal overhead over native regex
- Composable: Build complex parsers from simple patterns
- Tree-shakeable: Import only what you need with modular exports
Modular Imports
The library supports selective imports for optimal bundle size, especially useful in buildless environments:
// Import only what you need
import { splitStatements } from 'nested-regex-groups/split-statements';
import { parsePatterns } from 'nested-regex-groups/parse-patterns';
// Or import everything (backward compatible)
import { splitStatements, parsePatterns } from 'nested-regex-groups';
Available Subpath Exports
Core Utilities:
- __INLINE_CODE_3__ - Convert dot-notation keys to nested objects
- __INLINE_CODE_4__ - Merge multiple parse results
- __INLINE_CODE_5__ - Split paragraphs into statements
Core Parsing:
- __INLINE_CODE_6__ - Core parser with dot notation support
- __INLINE_CODE_7__ - Try multiple patterns + create parser factory
Runtime Pattern Parsing:
- __INLINE_CODE_8__ - Parse patterns from strings/JSON config (includes parsePattern and parsePatterns)
Flat Group Parsing:
- __INLINE_CODE_9__ - Parse with flat groups (no nesting)
- __INLINE_CODE_10__ - Parse multiple statements with flat groups
Nested Statement Parsing:
- __INLINE_CODE_11__ - Parse multiple statements with nested groups
Template Tags:
- __INLINE_CODE_12__ - Template tag API (rx, rxPattern, rxParser)
Buildless Environment Example
<script type="module">
// Only loads split-statements.js (~1KB) instead of full library (~15KB)
import { splitStatements } from './node_modules/nested-regex-groups/split-statements.js';
const statements = splitStatements('First. Second. Third.');
console.log(statements); // ['First', 'Second', 'Third']
</script>
Quick Start
JSON Config (Recommended for Runtime)
Perfect for configuration-driven applications:
import { parsePatterns } from 'nested-regex-groups';
// Load from JSON file
const config = {
patterns: [
{
name: 'email',
pattern: '^(?<user.name>\\w+)@(?<user.domain>\\w+)
Template Tag (Recommended for Code)
The cleanest way for code-based patterns:
;
const result = parser('John Doe');
if (result.success) {
console.log(result.value);
// { person: { name: { first: 'John', last: 'Doe' } } }
}
Multiple Patterns
,
rxPattern('username')`^(?<user.name>\w+)nested-regex-groups
A lightweight TypeScript library that extends JavaScript's regular expressions with dot notation in capture group names to produce nested object structures.
Why?
Standard regex named capture groups return flat objects:
const match = 'john@example.com'.match(/^(?<name>\w+)@(?<domain>\w+\.\w+)$/);
console.log(match.groups);
// { name: 'john', domain: 'example.com' }
With __INLINE_CODE_0__, use dot notation to create nested structures:
import { rx } from 'nested-regex-groups/template';
const parser = rx`^(?<user.name>\w+)@(?<user.domain>\w+\.\w+)nested-regex-groups
A lightweight TypeScript library that extends JavaScript's regular expressions with dot notation in capture group names to produce nested object structures.
Why?
Standard regex named capture groups return flat objects:
const match = 'john@example.com'.match(/^(?<name>\w+)@(?<domain>\w+\.\w+)$/);
console.log(match.groups);
// { name: 'john', domain: 'example.com' }
With __INLINE_CODE_0__, use dot notation to create nested structures:
;
const result = parser('john@example.com');
console.log(result.value);
// { user: { name: 'john', domain: 'example.com' } }
Installation
npm install nested-regex-groups
Features
- Dot notation in capture group names: __INLINE_CODE_1__ → __INLINE_CODE_2__
- Multiple pattern matching: Try patterns in priority order
- Zero dependencies: Tiny footprint
- Type-safe: Full TypeScript support with type inference
- Fast: Minimal overhead over native regex
- Composable: Build complex parsers from simple patterns
- Tree-shakeable: Import only what you need with modular exports
Modular Imports
The library supports selective imports for optimal bundle size, especially useful in buildless environments:
// Import only what you need
import { splitStatements } from 'nested-regex-groups/split-statements';
import { parsePatterns } from 'nested-regex-groups/parse-patterns';
// Or import everything (backward compatible)
import { splitStatements, parsePatterns } from 'nested-regex-groups';
Available Subpath Exports
Core Utilities:
- __INLINE_CODE_3__ - Convert dot-notation keys to nested objects
- __INLINE_CODE_4__ - Merge multiple parse results
- __INLINE_CODE_5__ - Split paragraphs into statements
Core Parsing:
- __INLINE_CODE_6__ - Core parser with dot notation support
- __INLINE_CODE_7__ - Try multiple patterns + create parser factory
Runtime Pattern Parsing:
- __INLINE_CODE_8__ - Parse patterns from strings/JSON config (includes parsePattern and parsePatterns)
Flat Group Parsing:
- __INLINE_CODE_9__ - Parse with flat groups (no nesting)
- __INLINE_CODE_10__ - Parse multiple statements with flat groups
Nested Statement Parsing:
- __INLINE_CODE_11__ - Parse multiple statements with nested groups
Template Tags:
- __INLINE_CODE_12__ - Template tag API (rx, rxPattern, rxParser)
Buildless Environment Example
<script type="module">
// Only loads split-statements.js (~1KB) instead of full library (~15KB)
import { splitStatements } from './node_modules/nested-regex-groups/split-statements.js';
const statements = splitStatements('First. Second. Third.');
console.log(statements); // ['First', 'Second', 'Third']
</script>
Quick Start
JSON Config (Recommended for Runtime)
Perfect for configuration-driven applications:
import { parsePatterns } from 'nested-regex-groups';
// Load from JSON file
const config = {
patterns: [
{
name: 'email',
pattern: '^(?<user.name>\\w+)@(?<user.domain>\\w+)
Template Tag (Recommended for Code)
The cleanest way for code-based patterns:
import { rx } from 'nested-regex-groups/template';
const parser = rx`^(?<person.name.first>\w+)\s+(?<person.name.last>\w+)nested-regex-groups
A lightweight TypeScript library that extends JavaScript's regular expressions with dot notation in capture group names to produce nested object structures.
Why?
Standard regex named capture groups return flat objects:
const match = 'john@example.com'.match(/^(?<name>\w+)@(?<domain>\w+\.\w+)$/);
console.log(match.groups);
// { name: 'john', domain: 'example.com' }
With __INLINE_CODE_0__, use dot notation to create nested structures:
import { rx } from 'nested-regex-groups/template';
const parser = rx`^(?<user.name>\w+)@(?<user.domain>\w+\.\w+)nested-regex-groups
A lightweight TypeScript library that extends JavaScript's regular expressions with dot notation in capture group names to produce nested object structures.
Why?
Standard regex named capture groups return flat objects:
const match = 'john@example.com'.match(/^(?<name>\w+)@(?<domain>\w+\.\w+)$/);
console.log(match.groups);
// { name: 'john', domain: 'example.com' }
With __INLINE_CODE_0__, use dot notation to create nested structures:
;
const result = parser('john@example.com');
console.log(result.value);
// { user: { name: 'john', domain: 'example.com' } }
Installation
npm install nested-regex-groups
Features
- Dot notation in capture group names: __INLINE_CODE_1__ → __INLINE_CODE_2__
- Multiple pattern matching: Try patterns in priority order
- Zero dependencies: Tiny footprint
- Type-safe: Full TypeScript support with type inference
- Fast: Minimal overhead over native regex
- Composable: Build complex parsers from simple patterns
- Tree-shakeable: Import only what you need with modular exports
Modular Imports
The library supports selective imports for optimal bundle size, especially useful in buildless environments:
// Import only what you need
import { splitStatements } from 'nested-regex-groups/split-statements';
import { parsePatterns } from 'nested-regex-groups/parse-patterns';
// Or import everything (backward compatible)
import { splitStatements, parsePatterns } from 'nested-regex-groups';
Available Subpath Exports
Core Utilities:
- __INLINE_CODE_3__ - Convert dot-notation keys to nested objects
- __INLINE_CODE_4__ - Merge multiple parse results
- __INLINE_CODE_5__ - Split paragraphs into statements
Core Parsing:
- __INLINE_CODE_6__ - Core parser with dot notation support
- __INLINE_CODE_7__ - Try multiple patterns + create parser factory
Runtime Pattern Parsing:
- __INLINE_CODE_8__ - Parse patterns from strings/JSON config (includes parsePattern and parsePatterns)
Flat Group Parsing:
- __INLINE_CODE_9__ - Parse with flat groups (no nesting)
- __INLINE_CODE_10__ - Parse multiple statements with flat groups
Nested Statement Parsing:
- __INLINE_CODE_11__ - Parse multiple statements with nested groups
Template Tags:
- __INLINE_CODE_12__ - Template tag API (rx, rxPattern, rxParser)
Buildless Environment Example
<script type="module">
// Only loads split-statements.js (~1KB) instead of full library (~15KB)
import { splitStatements } from './node_modules/nested-regex-groups/split-statements.js';
const statements = splitStatements('First. Second. Third.');
console.log(statements); // ['First', 'Second', 'Third']
</script>
Quick Start
JSON Config (Recommended for Runtime)
Perfect for configuration-driven applications:
import { parsePatterns } from 'nested-regex-groups';
// Load from JSON file
const config = {
patterns: [
{
name: 'email',
pattern: '^(?<user.name>\\w+)@(?<user.domain>\\w+)
Template Tag (Recommended for Code)
The cleanest way for code-based patterns:
;
const result = parser('John Doe');
if (result.success) {
console.log(result.value);
// { person: { name: { first: 'John', last: 'Doe' } } }
}
Multiple Patterns
]);
const result1 = parser('john@example.com');
// { success: true, pattern: 'email', value: { user: { name: 'john', domain: 'example.com' } } }
const result2 = parser('john');
// { success: true, pattern: 'username', value: { user: { name: 'john' } } }
API
Statements Parsing (Multiple Statements in Paragraphs)
Parse paragraphs containing multiple statements separated by periods, with support for nested object structures.
__INLINE_CODE_13__
Splits a paragraph into individual statements based on period delimiters.
import { splitStatements } from 'nested-regex-groups';
const statements = splitStatements('First. Second. Third.');
// ['First', 'Second', 'Third']
// Handles optional chaining and escaped periods
splitStatements('Check #obj?.prop. Use file\\.txt.');
// ['Check #obj?.prop', 'Use file.txt']
Rules:
- Splits on __INLINE_CODE_14__ followed by whitespace or end of string
- Ignores __INLINE_CODE_15__ (optional chaining)
- Ignores __INLINE_CODE_16__ (escaped period - becomes __INLINE_CODE_17__ in output)
- Trailing period on last statement is optional
__INLINE_CODE_18__
Parses a single statement using flat group patterns (no dots in group names).
import { parseGroupedCaptures } from 'nested-regex-groups';
const patterns = [
{ name: 'comparison', pattern: '^(?<trigger>on|off)\\s+when\\s+(?<lhs>#\\w+)\\s+eq\\s+(?<rhs>#\\w+)
Use when: You need flat objects without nesting.
__INLINE_CODE_19__
Parses multiple statements with flat group patterns.
import { parseGroupedCaptureStatements } from 'nested-regex-groups';
const patterns = [
{ name: 'comparison', pattern: '^(?<trigger>on|off)\\s+when\\s+(?<lhs>#\\w+)\\s+eq\\s+(?<rhs>#\\w+)
__INLINE_CODE_20__
Parses multiple statements with nested group patterns (dots in group names).
import { parsePatternStatements } from 'nested-regex-groups';
const patterns = [
{ name: 'comparison', pattern: '^(?<trigger>on|off)\\s+when\\s+(?<lhs.id>#\\w+)\\s+eq\\s+(?<rhs.id>#\\w+)
Use when: You need nested objects from multiple statements.
Default Values
Both __INLINE_CODE_21__ and __INLINE_CODE_22__ support default values for optional capture groups. This is useful when you want to provide fallback values for groups that might not match.
import { parsePatternStatements } from 'nested-regex-groups';
const patterns = [
{
name: 'comparison',
pattern: '^(?<trigger>on|off)?\\s*when\\s+(?<lhs.id>#\\w+)\\s+eq\\s+(?<rhs.id>#\\w+)
Key behaviors:
- Default values are applied when optional groups don't match (return __INLINE_CODE_23__)
- Parsed values always override defaults
- For nested patterns, use dot notation in default keys (e.g., __INLINE_CODE_24__)
- For flat patterns, use simple keys (e.g., __INLINE_CODE_25__)
__INLINE_CODE_26__
Convenience alias for __INLINE_CODE_27__ (the most common use case).
import { parseParagraph } from 'nested-regex-groups';
const result = parseParagraph('on when #foo eq #bar. off when #baz.', patterns);
__INLINE_CODE_28__
Return type for statements parsing functions:
interface StatementsResult<T = any> {
success: boolean; // true if all statements parsed successfully
statements: Array<{
pattern?: string; // Name of matched pattern
value?: T; // Parsed value (if successful)
error?: string; // Error message (if failed)
matched?: string; // Matched text
}>;
}
Example: Real-world be-switched paragraph
import { parsePatternStatements } from 'nested-regex-groups';
const patterns = [
{
name: 'fullComparison',
pattern: '^(?<trigger>on|off)\\s+when\\s+(?<lhs.id>#\\w+)(?:::(?<lhs.event>\\w+))?(?:\\?\\.(?<lhs.prop>\\w+))?\\s+(?<op>eq|gt|lt)\\s+(?<rhs.id>#\\w+)(?:::(?<rhs.event>\\w+))?(?:\\?\\.(?<rhs.prop>\\w+))?
See examples/statements-usage.ts for more examples.
Runtime Parsing (Recommended for JSON Config)
__INLINE_CODE_29__
Parses a regex pattern string with dot notation and creates a parser. Perfect for loading patterns from JSON config files.
import { parsePattern } from 'nested-regex-groups';
// From JSON config
const config = { pattern: "^(?<user.name>\\w+)@(?<user.domain>\\w+)$" };
const parser = parsePattern(config.pattern);
const result = parser('john@example.com');
Parameters:
- __INLINE_CODE_30__ - Regex pattern with dots in group names
- __INLINE_CODE_31__ - Optional name for error messages
Use when:
- Loading patterns from JSON files
- Patterns stored as strings in config
- Dynamic pattern loading at runtime
__INLINE_CODE_32__
Creates a multi-pattern parser from JSON-like configuration objects.
import { parsePatterns } from 'nested-regex-groups';
const config = {
patterns: [
{ name: 'email', pattern: "^(?<user.name>\\w+)@(?<user.domain>\\w+)$" },
{ name: 'username', pattern: "^(?<user.name>\\w+)$" }
]
};
const parser = parsePatterns(config.patterns);
Use when:
- Loading multiple patterns from JSON
- Configuration-driven applications
- Patterns need to be updated without code changes
See JSON_CONFIG.md for complete guide.
Template Tag API (Recommended for Code)
__INLINE_CODE_33__
Template tag for creating single-pattern parsers with dot notation.
import { rx } from 'nested-regex-groups/template';
const parser = rx`^(?<user.name>\w+)@(?<user.domain>\w+)nested-regex-groups
A lightweight TypeScript library that extends JavaScript's regular expressions with dot notation in capture group names to produce nested object structures.
Why?
Standard regex named capture groups return flat objects:
const match = 'john@example.com'.match(/^(?<name>\w+)@(?<domain>\w+\.\w+)$/);
console.log(match.groups);
// { name: 'john', domain: 'example.com' }
With __INLINE_CODE_0__, use dot notation to create nested structures:
import { rx } from 'nested-regex-groups/template';
const parser = rx`^(?<user.name>\w+)@(?<user.domain>\w+\.\w+)nested-regex-groups
A lightweight TypeScript library that extends JavaScript's regular expressions with dot notation in capture group names to produce nested object structures.
Why?
Standard regex named capture groups return flat objects:
const match = 'john@example.com'.match(/^(?<name>\w+)@(?<domain>\w+\.\w+)$/);
console.log(match.groups);
// { name: 'john', domain: 'example.com' }
With __INLINE_CODE_0__, use dot notation to create nested structures:
;
const result = parser('john@example.com');
console.log(result.value);
// { user: { name: 'john', domain: 'example.com' } }
Installation
npm install nested-regex-groups
Features
- Dot notation in capture group names: __INLINE_CODE_1__ → __INLINE_CODE_2__
- Multiple pattern matching: Try patterns in priority order
- Zero dependencies: Tiny footprint
- Type-safe: Full TypeScript support with type inference
- Fast: Minimal overhead over native regex
- Composable: Build complex parsers from simple patterns
- Tree-shakeable: Import only what you need with modular exports
Modular Imports
The library supports selective imports for optimal bundle size, especially useful in buildless environments:
// Import only what you need
import { splitStatements } from 'nested-regex-groups/split-statements';
import { parsePatterns } from 'nested-regex-groups/parse-patterns';
// Or import everything (backward compatible)
import { splitStatements, parsePatterns } from 'nested-regex-groups';
Available Subpath Exports
Core Utilities:
- __INLINE_CODE_3__ - Convert dot-notation keys to nested objects
- __INLINE_CODE_4__ - Merge multiple parse results
- __INLINE_CODE_5__ - Split paragraphs into statements
Core Parsing:
- __INLINE_CODE_6__ - Core parser with dot notation support
- __INLINE_CODE_7__ - Try multiple patterns + create parser factory
Runtime Pattern Parsing:
- __INLINE_CODE_8__ - Parse patterns from strings/JSON config (includes parsePattern and parsePatterns)
Flat Group Parsing:
- __INLINE_CODE_9__ - Parse with flat groups (no nesting)
- __INLINE_CODE_10__ - Parse multiple statements with flat groups
Nested Statement Parsing:
- __INLINE_CODE_11__ - Parse multiple statements with nested groups
Template Tags:
- __INLINE_CODE_12__ - Template tag API (rx, rxPattern, rxParser)
Buildless Environment Example
<script type="module">
// Only loads split-statements.js (~1KB) instead of full library (~15KB)
import { splitStatements } from './node_modules/nested-regex-groups/split-statements.js';
const statements = splitStatements('First. Second. Third.');
console.log(statements); // ['First', 'Second', 'Third']
</script>
Quick Start
JSON Config (Recommended for Runtime)
Perfect for configuration-driven applications:
import { parsePatterns } from 'nested-regex-groups';
// Load from JSON file
const config = {
patterns: [
{
name: 'email',
pattern: '^(?<user.name>\\w+)@(?<user.domain>\\w+)
Template Tag (Recommended for Code)
The cleanest way for code-based patterns:
import { rx } from 'nested-regex-groups/template';
const parser = rx`^(?<person.name.first>\w+)\s+(?<person.name.last>\w+)nested-regex-groups
A lightweight TypeScript library that extends JavaScript's regular expressions with dot notation in capture group names to produce nested object structures.
Why?
Standard regex named capture groups return flat objects:
const match = 'john@example.com'.match(/^(?<name>\w+)@(?<domain>\w+\.\w+)$/);
console.log(match.groups);
// { name: 'john', domain: 'example.com' }
With __INLINE_CODE_0__, use dot notation to create nested structures:
import { rx } from 'nested-regex-groups/template';
const parser = rx`^(?<user.name>\w+)@(?<user.domain>\w+\.\w+)