text_parser
2.4.0, released 2 years ago by kaboc.cc
A Dart package for parsing text flexibly using multiple regular expression patterns.
What it does
It parses text into a structured list of text elements based on preset or custom regular expression patterns. It supports features like groups capture, synchronous parsing, and background execution using isolates.
AI-written summary of version 2.4.0, based on the package's README and metadata. Report an inaccuracy
Use it when
- You need to detect and extract URLs, email addresses, or phone numbers from text.
- You want to parse custom markdown or HTML elements using regular expressions.
- You need to parse large texts without blocking the main UI thread.
Skip it when
- You need a full context-free grammar parser (use petitparser instead).
- You are parsing heavy structured documents like arbitrary XML or complex JSON where dedicated parsers are safer.
Strengths
- Includes useful preset matchers for URLs, emails, and phone numbers.
- Supports running parsing tasks in an isolate to prevent UI jank.
- Allows custom matchers and exact string matching with escaped regex characters.
Weaknesses
- Reliance on regular expressions can become hard to maintain for highly complex nested grammars.
- Named capture groups lose their names in the resulting groups list.
Setup
- Kind
- Pure Dart
- Effort
- Low
- Code generation
- No
- Direct dependencies
- 1
import 'package:text_parser/text_parser.dart';
void main() {
const text = 'Contact us at support@example.com or visit https://example.com';
final parser = TextParser(
matchers: const [
EmailMatcher(),
UrlMatcher(),
],
);
final elements = parser.parseSync(text);
elements.forEach(print);
}Alternatives
Packages that do the same job and could replace text_parser.
- petitparser
Choose petitparser if you need a robust grammar-based parser rather than regular expression matching.
93Compare - xml
Choose xml if your specific parsing target is XML instead of generic text patterns.
92Compare
Works with
Packages commonly used together with text_parser: ones it builds on, ones built on it, and its own family.