Last active
March 3, 2021 07:41
-
-
Save VB10/dc1f004396cc230dc036d72940a90272 to your computer and use it in GitHub Desktop.
String Regex
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
class RegexConstants { | |
static RegexConstants _instance; | |
static RegexConstants get instance { | |
if (_instance == null) { | |
_instance = RegexConstants._init(); | |
} | |
return _instance; | |
} | |
RegexConstants._init(); | |
final String emailRegex = | |
r"^[a-zA-Z0-9.a-zA-Z0-9.!#$%&'*+-/=?^_`{|}~]+@[a-zA-Z0-9]+\.[a-zA-Z]+"; | |
final String passwordRegex = r"^.{4,}$"; | |
final String userNameRegex = r"^.{4,}$"; | |
} |
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
extension StringExtension on String { | |
bool get isValidEmail { | |
return RegExp(RegexConstants.instance.emailRegex).hasMatch(this) | |
? true | |
: false; | |
} | |
} |
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
main() { | |
regExp.allMatches(sampleText).forEach((text) { | |
print(text.group(firstValue)); | |
}); | |
} | |
final int firstValue = 0; | |
final String sampleText = """ | |
String: #09asd ext #qwe-123 #aıaı ext #şook. ext #aĞ_aİ ext #Ür_ç ext #Şan ext | |
#_a34_ ext #sSmiling face with heart-shaped eyesrt ext | |
#gökü ext #aıaı <link>http://google.com/#account</link> | |
"""; | |
final regExp = RegExp(r"(^|\s)(#[a-z0-9_şıöğçüŞİÖĞÇÜ]+)"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Sample olarak ise: "[email protected]".isValidEmail 👍