I want to clean up my code. I would like to remove duplicated -tags
An example:
var testString = '<div style="text-align: right;">text1</div><div style="text-align: right;">text2</div>', str;
str = testString.replace(/<div style="(.*?)">(.*?)<\/div><div style="$1">/g, '<div style="$1">$2<br>');
In my head str should now contain '<div style="text-align: right;">text1<br>text2</div>'.
I know i am wrong, but where?
Hope you guys understand me 🙂
You have to use a different style for the backreference variable,
\1instead of$1in the regex.Try this: