I am trying to test match a string if it is both singular and plural using javascript.
Because I need to use a variable I'm using RexExp like so but it's always returning true even if I use checksxcd or anything else, as long as check is there it passes.
let str = 'check'
let reg = new RegExp("(["+ str +"])(s\\b|\\b)", "g");
reg.test(check)
// Returns true
If I test this without using the str variable it works for only singluar and only plural of the word check as expected.
let reg = new RegExp(/([check])(s\b|\b)/, "g");
I'm assuming I have a syntax issue but I can't seem to find out what I'm doing wrong. Any help is appreciated.