In a javascript code want to match a string with regex to return boolean (if string meets the requirement).
The string should end with yes, no, or maybe non-case-sensitive and can be wrapped with (or only at one side) a double-quote. so any string that ends with "Yes", "yes", yes, "YES", etc. is acceptable.
I have the following which is wrong. How should I construct the regex, or is it a good way in javascript?
function test(){
var str =document.getElementById("str").value;
const regex = /.*\"?[YES|NO|MAYBE]\"?$/gmi;
const result = new RegExp(regex).test(str);
console.log(result);
}
<input type="text" id="str" name="str" value=""/>
<input type="button" value="test" onclick="test()"/>