I’m having trouble finding a regex solution for a table search result. I tried the regex below, but it did not work as expected.
const regex = new RegExp(
searchTerm
?.toString()
.replace(/[.*+?^${}()|[]\]/g, "\$&")
.replace(/s+/g, "|") + ",?",
"gi"
);
How do I highlight 2,47 in the preceding example?
const regex = new RegExp(
247
?.toString()
.replace(/[.*+?^${}()|[]\]/g, "\$&")
.replace(/s+/g, "|") + ",?",
"gi"
);
console.log('247','247'.match(regex))
console.log('2,47','2,47'.match(regex))
console.log('2.47','2.47'.match(regex))