const regex = /((?<=\s)data-[^="]+?=".+(?=["]\s)")|((?<=\s)(?:data-[^=]+?)=".+?(?=>))|((?<=\s)(?:data-[^=]+?)="[^>]+?(?=>))/g;
// Alternative syntax using RegExp constructor
// const regex = new RegExp('((?<=\\s)data-[^="]+?=".+(?=["]\\s)")|((?<=\\s)(?:data-[^=]+?)=".+?(?=>))|((?<=\\s)(?:data-[^=]+?)="[^>]+?(?=>))', 'g')
const str = `<p><style type="text/css"><!--td {border: 1px solid #ccc;}br {mso-data-placement:same-cell;}--></style><span style="font-size:10pt;font-family:Calibri, Arial;" data-sheets-value="{"1":2,"2":"When doing a Future trade workflow, and selecting this Future asset to be traded on, a vos displayed showing that the Futures Type (which is the asset subtype) does not have Geneva ID on it. After some investigation, turns out that the actual Futures subtype list does not contain the list item \\"Physical index future.\\", which is currently showing for Asset ID 3175, as seen in attached Picture 2. "}" data-sheets-userformat="{"2":13249,"3":{"1":0},"9":0,"10":0,"11":4,"12":0,"15":"Calibri","16":10}">When doing a Future trade workflow, and selecting this Future asset to be traded on, a vos displayed showing that the Futures Type (which is the asset subtype) does not have Geneva ID on it. After some investigation, turns out that the actual Futures subtype list does not contain the list item "Physical index future.", which is currently showing for Asset ID 3175, as seen in attached Picture 2</span></p>`;
// Reset `lastIndex` if this regex is defined globally
// regex.lastIndex = 0;
let m;
while ((m = regex.exec(str)) !== null) {
// This is necessary to avoid infinite loops with zero-width matches
if (m.index === regex.lastIndex) {
regex.lastIndex++;
}
// The result can be accessed through the `m`-variable.
m.forEach((match, groupIndex) => {
console.log(`Found match, group ${groupIndex}: ${match}`);
});
}
Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for JavaScript, please visit: https://developer.mozilla.org/en/docs/Web/JavaScript/Guide/Regular_Expressions