I have a string with the name last name and date. They can have 4 types:

  1. Victor Potryshkin 1998.
  2. 1998 - Victor Patryshkin
  3. Victor Potryshkin 1998.
  4. 1998 - Victor Patryshkin.

How can I match one regular expression to get a surname, first name and date without the word "year (s)"?

  • @Visman, fixed - user238739
  • What dialect of regular expressions do you need? - mymedia
  • @mymedia, in terms of which dialect? - user238739
  • There are several different regular expression syntaxes . What language do you write? - mymedia
  • @mymedia, php :) - user238739

2 answers 2

Here it is possible:

(.+) (.+) (\d{4}) года?\.?|(\d{4}) года? - (.+) (.+) 

A live example: https://regex101.com/r/5eZrNR/3

  • thanks a lot - user238739

The variant with the data return in the same group regardless of where the year was written:

 /(?=.*?(\p{L}+)\s+(\p{L}+)).*?(\d+)\s+год/u 

Test https://regex101.com/r/OeJOIQ/1

PS For UTF-8 encoding and for the names and surnames consisting of letters :) If there is a dash in the name / surname, this regular schedule works with errors!