sorry for my english
I am trying replace everything that is not %d, %m or %Y from a string, I have been trying but I do not get it, here is my best attempt code:
var old_string = "%l %d de %M de %Y (Semana %W)";
string = old_string.replace(/[^(%d|%m|%Y)]/g, " ");
alert(old_string + " <----> " + string);
Some help?
What am I doing wrong?
If I understand correctly, you want to the substrings
%d,%mand%Yfrom your string. I assume you want one space between each match, and want to retain the original order of occurrence.You can do this using
String.match()andArray.join(), like so:Edit: here is a working demo: http://jsfiddle.net/PPvG/Gv3rX/1/
Edit (2): I realised the regular expression could be simplified further.