Last active
May 4, 2018 21:45
-
-
Save Stargator/ee2aa77274a28caf2447505bc4661784 to your computer and use it in GitHub Desktop.
Lookbehind in Dart
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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