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");
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");
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.
texto.replace(/(\d+) day(s?) ago/i, "Hace $1 dia$2").Should be
texto = texto.replace(/(\d+) days? ago/, "Hace $1 dia");
texto = texto.replace(/(\d+)\s+?days?\s+?ago/i, "Hace $1 dia");. But I think the asker doesn't have those scenarios, so keeping the regexp pattern simple runs much faster.texto.replace(/(\d+) day(s?) ago/i, "hace $1 día$2").