I have the following statement:
if (new RegExp("\\b" + product.toLowerCase() + "\\b").test(cellVal.toLowerCase())) {
console.log(product.toLowerCase() + " : " + cellVal.toLowerCase());
}
I'm having an issue with products that are similar. I have the following products that are causing an issue:
- tpd
- tpd - activity
What I'm finding is that the test
statement is passing as true when tpd or tpd - activity is passed in and tested against each other.
What I would like is if tpd is found as a whole word then the test should pass. If tpd - activity is found then that should pass. But what is happening is that tpd is also picking up a match in tpd - activity. I thought the \\b
would account for this scenario.
product
is coming from a database list and both products are valid. cellVal
is the text from an HTML table.
Any ideas?