rich_string_parser 1.0.1 copy "rich_string_parser: ^1.0.1" to clipboard
rich_string_parser: ^1.0.1 copied to clipboard

A dart string parser for parsing multible different formats.

example/rich_string_parser_example.dart

import 'package:rich_string_parser/rich_string_parser.dart';

class OwnMatch extends ParserMatch {
  String match;
  OwnMatch(
    this.match,
  ): super(match);
}

class OwnParser extends Parser {
  RegExp regex = RegExp(
    '(hello)',
    multiLine: true,
    unicode: true
  );

  @override
  OwnMatch converter(String own) {
    return OwnMatch(
      own
    );
  }
}

void main() {
  // single parser
  var singleParser = 'hello world example@example.com asd';
  List<dynamic> singleParserResult = richStringParser(
    singleParser,
    [ EmailParser() ]
  );

  // => ['hello world ', Instance of 'EmailMatch', ' asd']
  print(singleParserResult);

  // single parser
  var multibleParsers = 'hello @(123|example) world example@example.com asd';
  List<dynamic> multibleParsersResult = richStringParser(
    multibleParsers,
    [ EmailParser(), MentionParser() ]
  );

  // => ['hello ', Instance of 'MentionMatch', ' world ',  Instance of 'EmailMatch', ' asd']
  print(multibleParsersResult);

  // createParser: see OwnParser
  var own = 'hello world';
  List<dynamic> ownResult = richStringParser(
    own,
    [ OwnParser() ]
  );

  // => [Instance of 'OwnMatch', ' world']
  print(ownResult);
}
0
likes
35
pub points
0%
popularity

Publisher

unverified uploader

A dart string parser for parsing multible different formats.

Repository (GitHub)
View/report issues

License

MIT (LICENSE)

More

Packages that depend on rich_string_parser