Alex Nikitin
Alex Nikitin

Reputation: 931

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

Upvotes: 0

Views: 31

Answers (1)

Wiktor Stribiżew
Wiktor Stribiżew

Reputation: 626853

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.

Upvotes: 1

Related Questions