verbal_expressions 0.4.0

  • Readme
  • Changelog
  • Example
  • Installing
  • 76

Pub Package Build Status Coverage Status Github Issues

verbal_expressions #

A library for Dart developers that helps to construct difficult regular expressions.

Dart package info is here:

Quick start #

  var regex = VerbalExpression()
   ..maybe("www.").anythingBut(" ")

  // Create an example URL
  String url = "";

  // Use VerbalExpression's hasMatch() method to test if the entire string matches the regex
  regex.hasMatch(url); //True

  regex.toString();   // Outputs the regex used: ^http(s)?\\:\\/\\/(www\\.)?([^\\ ]*)\$

  var regex = VerbalExpression()..startOfLine()..then("abc")..or("def");

  var testString = "defzzz";
  //Use VerbalExpression's hasMatch() method to test if parts if the string match the regex
  regex.hasMatch(testString);   // true

Feel free to use any predefined char groups:

  var regex = VerbalExpression()

Define captures:

  var expression = VerbalExpression()
  RegExp regex = expression.toRegExp();

  var match = regex.firstMatch(text);
  print(; // returns "abcd"
  print(; // returns "b"

Examples #

More examples are in example file

Features and bugs #

Please find feature requests and bugs at the issue tracker.

Other implementations #

You can view all implementations on

[ Javascript - PHP - Python - C# - Objective-C - Ruby - Groovy - Haskell - C++ - ... (moarr) ]

Changelog #

0.4.0 #

  • Updated to Dart 2

0.3.1 #

  • Added .analysis_options and fixed common problems

0.3.0 #

  • breaking change: do not capture groups if it is not set explicitly using beginCapture/endCapture. More details
  • fixed group capturing
  • added lazy quantifiers
  • added Macintosh line break

0.2.0 #

  • breaking change: builder pattern approach replaced with method cascades. More details
  • set global search by default

0.1.0 #

  • Initial version, created by Ne4istb


library verbal_expressions_example.example;

import 'package:verbal_expressions/verbal_expressions.dart';

main() {
  var result = matchUrl(''); // true
  // ...

  String phoneWithSpace = "+097 234 243";
  result = matchTelephoneNumber(phoneWithSpace); //true
  // ...

  String phoneWithoutSpace = "+097234243";
  result = matchTelephoneNumber(phoneWithoutSpace); // true
  // ...

  String phoneWithDash = "+097-234-243";
  result = matchTelephoneNumber(phoneWithDash); // true
  // ...

  var domain = getDomain('');
  print(domain); // .com

  domain = getDomain('');
  print(domain); // .org

  var expression = VerbalExpression()

  var testString = expression.replace('Replace first DoG in the sentence but do not touch second dog', 'cat');

  print(testString); // Replace first cat in the sentence but do not touch second dog

String getDomain(String url) {
  var expression = VerbalExpression()
    ..anythingBut(" ")

  return expression.toRegExp().firstMatch(url).group(1);

bool matchTelephoneNumber(String number) {
  var regex = VerbalExpression()
    ..range([Range('0', '9')])
    ..maybe("-")..maybe(" ")

  return regex.hasMatch(number);

bool matchUrl(String url) {
  var regex = VerbalExpression()
    ..anythingBut(" ")

  return regex.hasMatch(url);

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:

  verbal_expressions: ^0.4.0

2. Install it

You can install packages from the command line:

with pub:

$ pub get

with Flutter:

$ flutter pub get

Alternatively, your editor might support pub get or flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:

import 'package:verbal_expressions/verbal_expressions.dart';
Describes how popular the package is relative to other packages. [more]
Code health derived from static analysis. [more]
Reflects how tidy and up-to-date the package is. [more]
Weighted score of the above. [more]
Learn more about scoring.

We analyzed this package on Apr 8, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.7.1
  • pana: 0.13.6

Health suggestions

Fix lib/src/range.dart. (-1 points)

Analysis of lib/src/range.dart reported 2 hints:

line 14 col 7: DO use curly braces for all flow control structures.

line 17 col 7: DO use curly braces for all flow control structures.

Format lib/src/verbal_expression.dart.

Run dartfmt to format lib/src/verbal_expression.dart.

Maintenance suggestions

Package is getting outdated. (-65.48 points)

The package was last published 86 weeks ago.

Update (-2 points)

1 image link is insecure (e.g., use https URLs instead.


Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.0.0 <3.0.0
Dev dependencies
test ^1.3.0