How does one extract a date from a string using javascript? It can be in the following formats:
31.07.2014
07.31.2014
2014.07.31 the same format but divi
function myFunction() {
var str = "Teen.Wolf.Orphaned.28.07.2014.HDTV";
var res = str.split(".");
var text = "";
var x;
for (x in res) {
if (!isNaN(res[x])) {
text += res[x];
if (text.length == 2) { text += ','}
else if (text.length == 5) { text += ',' }
}
}
document.write(text);
}
This will write "28,07,2014"
NOTE: only use this way if the strings will always be in a format similar to the ones you posted above.