I am not very well versed with coding. I have a set of strings in an array and I am trying to filter them out using regex but it's not working for me. I want my result array to return any string containing _number like _0, _01, _000
and the filter that I am using is
var myArray = ["bedroom_01", "bedroom_02", "bedroom" , "bathroom_01"];
var result = myArray.filter(name => name.includes("/_\d+/g"));
console.log(result);
The above code is returning me a blank array. Please let me know what am I doing wrong?
"/_\d+/g"->/_\d+/gyou're passing a string instead of a regex. EDIT: also you cannot use a regex in.inclues, you need to doregex.test(string).