I am trying to work out some regular expression which I have working in one direction but fails when i change the attributes.
What I am trying to achieve is find the value of align and replace this value into the class
var s = '<img src="" align="left" class="smart" title="title for reference" />';
var reg = new RegExp(/(?:align="(.*?)").*?(?:class="(.*)")/);
console.log( s.replace(reg ,'class="image-$1 $2"') );
this works fine and outputs
<img src="" class="image-left smart" title="title for reference" />
but if i alter the html placing the class before the align I just get the original html string