Skip to content

Instantly share code, notes, and snippets.

@Stargator
Last active May 4, 2018 21:45
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/ee2aa77274a28caf2447505bc4661784 to your computer and use it in GitHub Desktop.
Save Stargator/ee2aa77274a28caf2447505bc4661784 to your computer and use it in GitHub Desktop.
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 matched .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)}');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment