Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

161
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda