Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

154
Vistas
Get Full Date Only in Regex

I have strings that includes the dates. I wanted to get the full date only. If there's no year, just add the current year of 4 digits.

Sample

Nov 29 2019
abc 0 May 30 2020
ddd Apr 3 2021 efg
0 Jan 3 hellodewdde deded

https://regex101.com/r/pLUQNe/1

Regex

(?:Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec) \d{1,2}?)
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

You may use the following regex pattern:

(?:Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec) \d{1,2}(?: \d{4})?

var dates = ["Nov 29 2019", "abc 0 May 30 2020", "ddd Apr 3 2021 efg", "0 Jan 3 hellodewdde deded", "Green eggs and ham"];
var months = "(?:Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)";
var regex = new RegExp(months + " \\d{1,2}(?: \\d{4})?");
var matches = [];

for (var i=0; i < dates.length; ++i) {
    var date = dates[i].match(regex);
    if (date != null) {
        if (date[0].match(/ \d{4}$/)) {
            matches.push(date[0]);
        }
        else {
            matches.push(date[0] + " " + new Date().getFullYear());
        }
    }
}

console.log(matches);

The logic here is that we detect if the matching date has a ending 4 digit year. If not, then we append the current year to the month/day match.

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda