fancy_regex Pub

Utility functionalities to write Regular Expressions with simpler terms.


If you have trouble writing Regular Expressions by yourself, or you’re not really used tobuilt-in RegExp class, then youcan start learning to implement Regular Expressions using this package.

This package offers APIs to write Regular Expressions using a more verbose, but more humanelyreadable classes and methods.

If you’re already very proficient with writing Regular Expressions by yourself, you won’t reallyneed this package.

Getting started

Adding the dependency

dependencies:  fancy_regex: ^0.1.0


import 'package:fancy_regex/fancy_regex.dart';// Base Usagefinal RegExp exp = FancyRegex(  expression: RawExpression("Hello World",), // Any RegExpComponent);// Use the RegExp object for your pattern matching needs


The APIs available on this package, are implementable with two available approaches.

  • Builder Pattern: Instantiate a single base RegExpComponent expression, then it can beextended with provided extension methods.
  • Flutter Widget Tree Style: Each RegExpComponent implementing class here is capable ofwrapping another RegExpComponent expression in it.
import 'package:fancy_regex/fancy_regex.dart';// Example for writing expression: /\+628\d{8,13}/// In Dart's RegExp, it's declared as RegExp(r"\+628\d{8,13}",)// Widget Tree StyleRegExp treeExp = FancyRegex(  expression: SerialExpressions(    [      CharacterClass.literal("+",),      RawExpression("628",),      MatchRangedCount(        CharacterClass.digits(),        8,        end: 13,      ),    ],  ), // Any RegExpComponent);// Builder PatternRegExp builderExp = FancyRegex(  expression: CharacterClass.literal("+",).addRight(    RawExpression("628",),  ).addRight(    CharacterClass.digits().matchBetween(      start: 8, end: 13,    ),  ), );// Use the RegExp object for your pattern matching needs

See Example Section

Available APIs

See the documentation here

Additional information

  • As stated by most Regular Expression info bases out there, some uncommon expressions are not workinguniversally. Please consult on further references if certain expressions fail to work on certainplatforms.
  • If you find the APIs to be too cumbersome to use, or want to suggest something, or bug reports,feel free to raise an issue.


  • Look for more available RegEx operators not yet implemented out there
  • Write more concise, more easily understandable APIs
  • Improving documentation


View Github