I'm currently learning how to use RegEx. I couldn't find a tutorial (or didnt know where to look) for replacing the result with the previous content.
I've managed to get the regex for extracting foo and bar
<div foo bar=""></div>
I want to obtain:
<div data-foo data-bar=""></div>
Here's how I'm trying to do it:
str = str.replace(/[^<div ][^/div]\w+/g, 'data-$1');
However, $1 doesnt get replaced by foo and bar.
Can someone help me? I'm stuck here!
Thank you very much!