Skip to content

Instantly share code, notes, and snippets.

@mrmarcondes
Created December 1, 2011 11:14
Show Gist options
  • Save mrmarcondes/1415935 to your computer and use it in GitHub Desktop.
Save mrmarcondes/1415935 to your computer and use it in GitHub Desktop.
Exercício sobre expressões regulares
String.prototype.convertDateFormat = function() {
var pattern = /^(\d{1,2})\/(\d{1,2})\/(\d{4})/;
var str = "";
for (var i = 0; i < this.length; i++){
str += this[i];
}
return str.match(pattern)[3] + '-' + str.match(pattern)[2] + '-' + str.match(pattern)[1];
};
var a = "30/10/2000";
console.log(a.convertDateFormat());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment