dart_regex 0.0.1 copy "dart_regex: ^0.0.1" to clipboard
dart_regex: ^0.0.1 copied to clipboard

Type-safe DSL for building regular expressions in Dart using composable building blocks.

example/dart_regex_example.dart

import 'package:dart_regex/src/atoms.dart';
import 'package:dart_regex/src/dart_regex.dart';
import 'package:dart_regex/src/groups.dart';
import 'package:dart_regex/src/quantifiers.dart';

void main() {
  final email = 'email@gmail.com';

  final match1 = emailPattern.firstMatch(email)?.groups([0, 1, 2]);
  print(match1);

  final match2 = emailPatternDSL.firstMatch(email)?.groups([0, 1, 2]);
  print(match2);
}

final emailPattern = RegExp(r'(\w+)@([\w.\w]+)');

final DartRegex emailPatternDSL = DartRegex([
  CaptureGroup(
    OneOrMore(Word()),
  ),
  CharacterSet('@'),
  CaptureGroup(
    OneOrMore(
      AtomGroup(
        [Word(), CharacterSet('.'), Word()],
      ),
    ),
  ),
]);
6
likes
160
points
18
downloads

Publisher

unverified uploader

Weekly Downloads

Type-safe DSL for building regular expressions in Dart using composable building blocks.

Repository (GitHub)
View/report issues

Documentation

API reference

License

BSD-3-Clause (license)

More

Packages that depend on dart_regex