Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Stargator/8531db3b855bbbcd092faa16c1fd4908 to your computer and use it in GitHub Desktop.
Save Stargator/8531db3b855bbbcd092faa16c1fd4908 to your computer and use it in GitHub Desktop.
Condtional and Lookbehind in Dart
void main() {
// Lookbehind example
final String phrase = "fooback";
final RegExp lookbehindPattern = new RegExp(r'(?<=foo)back');
print('Does lookbehind work? ${lookbehindPattern.hasMatch(phrase)}');
// Negative Lookbehind example
// It would match .text or text= but not Me.text or FtextABC
final RegExp negativeLookbehind = new RegExp(r'(?<!(Me\.)|[frFR])(text)(?!\w)');
final String phrase1 = ".text";
final String phrase2 = "text=";
final String phrase3 = "Me.text";
final String phrase4 = "FtextABC";
print('Negative lookbehind test 1: ${negativeLookbehind.hasMatch(phrase1)}');
print('Negative lookbehind test 1: ${negativeLookbehind.hasMatch(phrase2)}');
print('Negative lookbehind test 1: ${negativeLookbehind.hasMatch(phrase3)}');
print('Negative lookbehind test 1: ${negativeLookbehind.hasMatch(phrase4)}');
RegExp condition = new RegExp(r'(?((?<=foo)back)[0-9]|[a-z])');
print('Conditional Test: ${condition.hasMatch('fooback')}');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment