I want to match multiple data-i18n
attributes with a JavaScript regexp.
I tried the following regexp :
var regexp = /(data\-i18n="[^"]+")/g;
which in my head seemed rather straight forward, but it ended up not working.
If you try to match on the following HTML tag :
<a random-attr="ok" data-i18n="first match" data-i18n="second match">my text</a>
doing an exec like this :
/(data\-i18n="[^"]+")/g.exec('<a random-attr="ok" data-i18n="first match" data-i18n="second match">my text</a>')
will raise the following issue :
- There are two matches, but they are actually duplicate matches.
The result is :
[ 'data-i18n="first match"',
'data-i18n="first match"',
index: 20,
input: '<a random-attr="ok" data-i18n="first match" data-i18n="second match">my text</a>' ]
- Any ideas on how to have multiple matches for my attribute ?
Thanks in advance !