Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Extract spesific date in string regex

I have following string

Документ подписан аналогом собственноручной подписи Клиента (простой электронной подписью): [349522252]
[01.12.2019][8605]
Дата подписания: 01.12.2019

I need to extract date so result should be 01.12.2019. I fugured out how to extract something between [...]

(?<=\[)(.*?)(?=\])

but it’s captured wrong enter image description here

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

You can use

(?<=\[)\d{1,2}\.\d{1,2}\.\d{2}(?:\d{2})?(?=\])

See the regex demo.

Details:

  • (?<=\[) – a positive lookbehind that matches a location that is immediately preceded with a [ char
    \d{1,2} – one or two digits
  • \. – a dot
  • \d{1,2}\. – one or two digits and a dot
  • \d{2}(?:\d{2})? – two or four digits
  • (?=\]) – a positive lookahead that matches a location that is immediately preceded with a ] char.
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading