N
N
Nikolai Chuprik2018-04-25 01:03:12
Regular Expressions
Nikolai Chuprik, 2018-04-25 01:03:12

How to check year strictly from 2 or 4 in the middle of string?

It is required to check for the presence of the year, which should occur in the middle of the string. Moreover, the year can be written both in two-digit form and in four-digit form ( 18 or 2018 ) in the range from 2000 to 2019.
If the year were a separate line, then there is no problem:
/^([01]\d|20[01]\d)$/
but if you remove the characters for the beginning and end of the line, then three-digit numbers, for example 201, begin to fall under the pattern. What advise?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
X
xmoonlight, 2018-04-25
@choupa

/(?:[^\d](20[01]\d)[^\d])|(?:[^\d]([01]\d)[^\d])/

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question