I’m trying to make a regex pattern that would return true for when the string ends with a single letter.
Hello dear - false
Hello D - true
HelloD - false
Tried /\[^/sA-Z\]/
but of course that did not work :(
CodePudding user response:
You should be using the end ($) flag
/\s[A-Za-z]$/
CodePudding user response:
Ends in single letter
function isAllaz() {
let a = ["Hello dear", "Hello D", "HelloD"];
let o = a.map(s => {return `${s} - ${(s.match(/^.* [A-Za-z]$/))? 'true': 'false'}`});
console.log(JSON.stringify(o));
}
Execution log
10:38:41 PM Notice Execution started
10:38:42 PM Info ["Hello dear - false","Hello D - true","HelloD - false"]
10:38:42 PM Notice Execution completed