0

Input String:

var input = '<div><mark contenteditable="false" data-tag="ORG" data-content="Productions" class="zd9371e2d05f">Leeward Productions<span class="zd9a858eba95"><span>ORG </span> <span class="zd2589570ddc">x </span></span></mark><p>Sample text</p></div>'

I tried the following regex

new RegExp('data-tag="(.*?)"', 'ig')
new RegExp('data-content="(.*?)"', 'ig')

I need regex for both (data-tag, data-content)'s attribute value. Please help.

Thank you!.

  • https://stackoverflow.com/questions/9213237/combining-regular-expressions-in-javascript Does this answer your question? – Vishal Dhawan Jul 04 '20 at 08:05
  • Have you considered parsing out the values of data attributes from the string without rendering it into DOM? [Here is a good example of how to use DOM Parser](https://stackoverflow.com/questions/30040319/how-to-execute-document-queryselectorall-on-a-text-string-without-inserting-it-i/30040354#30040354). Sorry if you absolutely need to use regex, I will update my answer accordingly. – mnewelski Jul 04 '20 at 08:08
  • Here is a [JS fiddle of the DOM Parser](https://jsfiddle.net/5mjv10w6/) method mentioned. – mnewelski Jul 04 '20 at 08:21
  • Thank you so much for sharing DOM Parser. It's working fine :). – S Kumaresan Jul 04 '20 at 09:35

0 Answers0