Goal:
I have an answer box that will take inputs from a user. To reduce the amount of possible correct answers I enter into the backend I would like to use a RegExp to ignore certain words/characters at the start and at the end of the answer.
So if the answer was: mountain. I would also accept: the mountain OR a mountain OR the mountains...
What I have tried:
bool checkAnswer(String answer) {
List _answers = widget.answers;
for (var i = 0; i < _answers.length; ++i) {
// This
_correctAnswer = RegExp("?!(the)|(an)|(a)?${widget.answers[i]}s?").hasMatch(answer);
if (_correctAnswer) {
return _correctAnswer;
}
}
return false;
}
This function looks at the user input and compares it to the answers I've inputted on the backend. The problem is that it also accepts individual characters 't,h,e'...etc