I've got to work a basic find string and add style eg. <button onclick="copyData(event)" class="${orders.test(match)}">${match}</button>
But I want to apply the same methodology to all four regex matches below; matching the corresponding .css style.
orders: example: 975612345678. range: 975600000000-975699999999
customers: example: 1712345678901. range: 1700000000000-1799999999999
emails: example: word@test.com, 01234@numbers.tk
items: example: 32101234, 1012345678. range: 00000000-99999999, range: 1000000000-1099999999
We can see that it misses regex for emails
and items
: range: 00000000-99999999.
const orders = /\b9756[0-9]{8}\b/;
const customers = /\b17[0-9]{11}\b/;
const emails = ??
const items = ?? and /\b10[0-9]{8}\b/;
for (var i = 0; i < list.length; i++) {
let text = list[i].textContent;
// Make the regex have boundary characters to ensure that it's checking against the whole number, rather than a part. example: 975612345678. range: 975600000000-975699999999
const orders = /\b9756[0-9]{8}\b/;
list[i].innerHTML = text.replace(
// Replace all number sequences in the text
/\d+/g,
// Replace by checking if the replacement text matches "const orders"(regex) to determine color
(match) => `<button onclick="copyData(event)" class="${orders.test(match)}">${match}</button>`
)
}
/*.true needs to be .orders */
.true {
background-color: green;
}
.orders {
background-color: green;
}
/* corresponding regex "orders, customers, emails and items" needs to match style */
.customers {
background-color: red;
}
.emails {
background-color: blue;
}
.items {
background-color: yellow;
}
Anyone who has an solution to the problem? I have found something at Replace multiple strings with multiple other strings, but haven't found a working solution. A demo can be checked at https://jsfiddle.net/rrggrr/rt96ghw2/14/