I’m trying to check for either numbers, ‘e’, ‘π’ or ‘ ‘ at the end of a String.
This is what I’m using: \s|[0-9]|e|π$
. This is the code:
final regex = RegExp(r'\s|[0-9]|e|π$');
if (regex.hasMatch(_expression)) { //_expression is the string
//body
}
This always returns true. What’s the error here?
>Solution :
Try with the following regular expression:
void main() {
final regex = RegExp(r'(\s|[0-9]|e|π)$');
print(regex.hasMatch('959**')); // false
print(regex.hasMatch('959')); // true
}