Created with <3 with dartpad.dev.
Created
January 19, 2024 04:54
-
-
Save matifdeveloper/921e32ade1150134a79b81f386f5fc9c to your computer and use it in GitHub Desktop.
Text Inside Brackets
This file contains 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
extension StringExtension on String { | |
String? getTextInsideBrackets() { | |
RegExp regExp = RegExp(r'\[([^\]]*)\]'); | |
RegExpMatch? match = regExp.firstMatch(this); | |
return match?.group(1); | |
} | |
} | |
void main() { | |
String a = "hello welcome [to] pakistan."; | |
String? textInsideBrackets = a.getTextInsideBrackets(); | |
if (textInsideBrackets != null) { | |
print(textInsideBrackets); | |
} else { | |
print("No text inside brackets found."); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment