Skip to content

Instantly share code, notes, and snippets.

@VB10
Last active March 3, 2021 07:41
Show Gist options
  • Save VB10/dc1f004396cc230dc036d72940a90272 to your computer and use it in GitHub Desktop.
Save VB10/dc1f004396cc230dc036d72940a90272 to your computer and use it in GitHub Desktop.
String Regex
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,}$";
}
extension StringExtension on String {
bool get isValidEmail {
return RegExp(RegexConstants.instance.emailRegex).hasMatch(this)
? true
: false;
}
}
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_şıöğçüŞİÖĞÇÜ]+)");
@VB10
Copy link
Author

VB10 commented Nov 3, 2020

Sample olarak ise: "[email protected]".isValidEmail 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment