So I have a regex:
const [keyword, setKeyword] = useState('')
const pattern = new RegExp('\\b' + filterkeyword.replace(/[^a-zA-Z0-9 ]/g, ""), 'i')
An item in the products array would look something like this:
{
name: 'Men's Shirts',
price: 123,
sale: 30,
...
}
basically, whenever a user types on an input, this keyword is being sent. I am then using
products.filter(x=> pattern.test(x.name)).map(product=> {return <Product />})
The issue I'm having here is that if the name of the product is "Men's Shirts" or "Women's Shirts" or anything that contains a {'}, the filter won't work anymore. Any idea how I can fix this issue?