I have the following situation: I'm looking for attributes in an HTML string.
I have the following regular expression that works well, but I want to get only unique results, of course, I can apply some filter to the array of results, but I think this is achieved with a pure regular expression.
https://regex101.com/r/UqCuJS/1
So, in this situation, the class returns twice, but I want only 1 time:
['class', 'data-text'] not ['class', 'data-text', 'class']
const html = `<div class="foo">
<span data-text="Some string" class="bar"></span>
</div>`
console.log(html.match(/[\w-:]+(?=\s*=\s*".*?")/g))
Run codeHide resulthttp://jsbin.com/bekibanisa/edit?js,console
source
share