Modify a reference numbered group to match against

Posted by StuperUser on Stack Overflow See other posts from Stack Overflow or by StuperUser
Published on 2011-11-23T17:25:26Z Indexed on 2011/11/23 17:50 UTC
Read the original article Hit count: 242

Filed under:

I want to match YYYY-YY for sequential years.

I at moment I'm trying to match where all the second YY is the 3rd and 4th characters in YYYY with 1 added to it.

So far I've got {19|20}(\d{2})-(\d{2}), but not sure how to use ? with reference to (1) or whether I'm going about this the right way and finding out the inevitable "unknown unknowns" (like YY99) with this approach?

Edit:

Matches: 2010-11,2011-12,2029-30
Not matches: 2010-12, 2010-09,2011-2,2011-2012

© Stack Overflow or respective owner

Related posts about regex