I know there are many questions answered with this title but I have not found any that fit what I'm looking for...
I need to use regex like this "/^ user input $/i" The user input can put the * regex character in front of or behind the text.
If I use the "new RegExp(user input, "i")" does not accomplish the requirements of ^ and $ and the user regex character *.
I had something like this:
var foo = {User input};
var arr = ['Lorem Ipsum', 'simply dummy text', 'nothing'];
arr = arr.filter(function(item){
return /^{foo content here}$/i.test(item);
});
Tests:
foo = "Lorem" -> array[]
foo = "Lorem*" -> array['Lorem Ipsum']
foo = "Dummy" -> array[]
foo = "*Dummy*" -> array['simply dummy text']
foo = "*" -> array['Lorem Ipsum', 'simply dummy text', 'nothing']
Many thanks.