How to make a regex for date format dd yyyy MMMM?

Good night friends;

A question please, how could I make a regex to capture the following date format:

dd yyyy MMMM

01 2022 Enero
23 2020 Febrero
12 2021 Marzo
20 2019 Abril
24 2020 Mayo
26 2018 Junio
27 2022 Julio
11 2021 Agosto
02 2017 Setiembre
16 2018 Octubre
18 2022 Noviembre
20 2020 Diciembre

I found the following on the web, but I can’t adapt it:

dd.mmm.YYYY
^(?:(?:31(/|-|.)(?:0?[13578]|1[02]|(?:Jan|Mar|May|Jul|Aug|Oct|Dec)))\1|(?:(?:29|30)(/|-|.)(?:0?[1,3-9]|1[0-2]|(?:Jan|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec))\2))(?:(?:1[6-9]|[2-9]\d)?\d{2})$|^(?:29(/|-|.)(?:0?2|(?:Feb))\3(?:(?:(?:1[6-9]|[2-9]\d)?(?:0[48]|[2468][048]|[13579][26])|(?:(?:16|[2468][048]|[3579][26])00))))$|^(?:0?[1-9]|1\d|2[0-8])(/|-|.)(?:(?:0?[1-9]|(?:Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep))|(?:1[0-2]|(?:Oct|Nov|Dec)))\4(?:(?:1[6-9]|[2-9]\d)?\d{2})$

try this
^(([0-9])|([0-2][0-9])|([3][0-1]))\ \d{4}\ (Enero|Febrero|Marzo|Abril|Mayo|Junio|Julio|Agosto|Setiembre|Octubre|Noviembre|Diciembre)$

1 Like

Thank you very much for responding @jack.chan , I tried in this case but it does not capture the date

“Casa grande s.a. recibió: S/ 5.00 Viernes 20 2022 Mayo 23:59 Destino Cssa grande s.a. Banco BCP - 985 123233773 0 33 Moneda Soles Origen Ahorro Soles 315 9665454 0 60 Número de operación 45021526”

Hi @Lynx

Take a look here at this Regex Pattern (preview it here).

Try this:
[0-9]{1,2} 20\d{2} (Enero|Febrero|Marzo|Abril|Mayo|Junio|Julio|Agosto|Setiembre|Octubre|Noviembre|Diciembre)

Your actual sample is different to what was originally provided, this is why @jack.chan’s pattern is not working. I have made a couple tweaks to simplify the pattern (imo) and it should be working now.

Cheers

Steve

2 Likes

Thanks a lot @Steven_McKeering

1 Like

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.