Reputation: 177
I want to replace a simple text like: 1 day ago to Hace 1 dia
I have tried the following code, but it does not work:
var texto = "1 day ago";
texto = texto.replace('/\d+(?=day ago)/', "Hace $1 dia");
Upvotes: 2
Views: 132
Reputation: 174947
var texto = "1 day ago";
texto = texto.replace(/(\d+) day(s?) ago/i, "Hace $1 dia$2");
I've expanded it a little to allow for "N days ago" as well.
Upvotes: 4