AngularJS Grunt image pattern
grunt-usemin > options - patterns
image
JS regexp
by Guillaume Seguin
HTML
<div id="before">Foo</div>
<br><br>
<div id="after">Foo</div>
JavaScript
function stringFormat(str) {
var reg = /<img[^\>]*[^\>\S]+ng\-src=['"][\{\}\:\w\s]*([^'"\)#]+)(#.+)?["']/gm,
result = str.replace(reg, function (match, src) {
console.log(match);
console.log(src);
var res = match.replace(src, '/images/logo.47dfa49e.jpg');
return res;
});;
return result;
}
var str = "<section id=\"login\"> <form name=\"flogin\" novalidate ng-class=\"{subscibe:isSubscribe || sso}\"> <div class=\"title\"> <img ng-src=\"{{ ::absUrl }}/images/logo.jpg\" alt=\"\" /> <h1>Anagène</h1> </div> <p ng-class=\"{'highlight': true, 'editable-error': isError}\" ng-bind-html=\"message\"></p> <input type=\"text\" ng-model=\"credentials.username\" placeholder=\"Votre identifiant\" required ng-hide=\"isSubscribe || sso\" autofocus> <input type=\"password\" ng-model=\"credentials.password\" placeholder=\"Votre mot de passe\" required ng-hide=\"isSubscribe || sso\"> <button type=\"button\" class=\"submit\" ng-click=\"isSubscribe ? subscribe() : login()\" ng-disabled=\"flogin.$invalid && !isSubscribe\" data-placement=\"bottom-left\" bs-tooltip=\"{title: 'Raccourcis clavier : touche Entrée'}\" ng-bind=\"isSubscribe || sso ? sso ? 's\'authentifier' : 's\'abonner' : 'Connexion'\"></button> <a href=\"#/login/password/forgot\" class=\"password\" ng-hide=\"isSubscribe || sso\">Mot de passe oublié</a> </form></section>";
$('#before').text( str );
$('#after').text(stringFormat( str ));