I've been handed a JS regex function that is run on a form to correctly brand products on a page.
I'm rebuilding the page using angularJS and need to similarly apply that regex as each product name is output but I'm unsure how best to do this...
so I am writing out the products in my ng-repeat simply as {{product.name}} but how can I apply this branding ruleset to this output...
The following regex checks for branding pattern and applies a html style as needed:
var regex = /(Brand1|Brand2) ([-\w\s+]+)([™®])/
val = val.replace(regex, "$1 <strong>$2$3</strong>");
It may help if I post the full JS as it does a sense check first to see if TM or (R) is in the product name in which case the branding check/regex should be used.
if (val.indexOf('™') !== -1 || val.indexOf('®') !== -1) {
// Check for exceptions
if (val.indexOf('Special BRAND 1') !== -1 || val.indexOf('Special BRAND 2') !== -1) {
val = val.replace("Special BRAND 1™", "Special BRAND <strong>1™</strong>");
val = val.replace("Special Brand 2™", "Special Brand <strong>2™</strong>");
} else {
/* The products not an exception so run regex
*/
var regex = /(Brand1|Brand2) ([-\w\s+]+)([™®])/
val = val.replace(regex, "$1 <strong>$2$3</strong>");
}
}