Package selection guidance compiled from public package information, community data, and project usage.
A Flutter/Dart package that extends RegExp functionality to recursively parse and process delimited text blocks, such as nested brackets or custom delimiters. It applies a pattern to each isolated block independently, enabling precise extraction and transformation of structured text within complex strings. Ideal for parsing nested syntax like templates, expressions, or markup languages. The implementation supports multiple platforms including mobile, web, and desktop, making it versatile for cross-platform applications requiring advanced text manipulation.
Use cases
Parsing nested templates
Extracting content from delimited blocks
Processing structured text with recursion
Implementing custom DSLs
Handling nested expressions in code
Text transformation in multi-layered strings
Key features
Recursive block isolation
Independent pattern application per block
Support for custom delimiters
Cross-platform compatibility
Simple API integration
Efficient text processing
Suitable for
Developers building template engines
Tools requiring nested text parsing
Applications with structured string data
DSL or language parser implementations
Text editors or code analyzers
Considerations
May not handle deeply nested structures efficiently
Requires careful delimiter design
Performance depends on input complexity
Limited to text-based patterns
Not suitable for non-recursive parsing needs
Potential stack overflow with extreme nesting
Original README
Original README snapshot from the linked source repository. Visit the repository for the latest content.
recursive_regex
An implementation of Dart's RegExp class that isolates delimited blocks
of text and applies the delimited pattern to each block separately.
The [RecursiveRegex] class implements Dart's [RegExp] class. As such,
it has all of the same methods as [RegExp] and can be used interchangeably
with [RegExp]s.
[RecursiveRegex] has 2 required parameters, [startDelimiter] and
[endDelimiter]. Both accept a [RegExp], must not be null, and
must not have identical patterns.
final regex = RecursiveRegex(
startDelimiter: RegExp(r'<'),
endDelimiter: RegExp(r'>'),
);
This [RecursiveRegex], if applied to a string, would capture every block
of text delimited by the < and > characters.
final input = 'a<b<c<d><e>f>g>h';
regex.allMatches(input); // ['<b<c<d><e>f>g>']
By default, only top-level blocks of delimited text are matched. To match
every block of delimited text, nested or not, [global] can be flagged true.
Delimited blocks of text are matched in the order that they're closed.
Note: [RecursiveRegex] is not optimized for parsing strings that do
not contain nested blocks of delimited text, [RegExp] would be more
efficient if you know the string doesn't contain any nested delimiters.
[prepended] & [appended] Patterns
[Pattern]s can be provided to [RecursiveRegex]'s [prepended] and [appended]
parameters to disqualify any matched set of delimiters that aren't lead and/or
followed by the provided [Pattern].
The block of text captured between the delimiters can be captured in a
named group by providing [RecursiveRegex] with a [captureGroupName].
final input = '<!ELEMENT [ some markup ]>';
final regex = RecursiveRegex(
startDelimiter: RegExp(r'<!(?<type>\w*)\s*\['),
endDelimiter: RegExp(r']>'),
captureGroupName: 'value',
);
print(regex.firstMatch(input).namedGroup('value')); // ' some markup '// Groups named within the delimiters can also be called.print(regex.firstMatch(input).namedGroup('type')); // 'ELEMENT'