Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3319626
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T22:50:49+00:00 2026-05-17T22:50:49+00:00

I received a change request and I’m unsure how to best approach it. If

  • 0

I received a change request and I’m unsure how to best approach it. If the client searches for something and they specify a year or year range greater than what we have in our database, I have to return the result that corresponds to the latest year range that we have.

Currently the results we have in the db all follow one of the following pattern:

Thing1 Thing2 S1 // There's some results with no year
Thing1 Thing2 2006-07 Series 6 // there's some results with 'Series X'
Thing1 Thing2 2006-2007 S12 RP // some resuls have SN or SN YZ
Thing1 Thing2 2020-21 S6 // some results don't have a full second year
Thing1 Thing2 2022-2024 S12
Thing1 Thing2 2024 Onwards // the result that matches the final year just has the year & 'Onwards'

There are more results for Thing1 Thing2 available in the world, going up to 2060, but we only keep +14 years worth of data, because after 14 years (say 2026 or 2028), the data is exactly the same as the years previous.

The maximum year we have, and the maximum year in existance increases by 2 years every 2 years. So in 2012, we’ll have Thing1 Thing2 2026 Onwards, and the maximum in existance will be 2062.

So basically, I need to identify when the client searches for [Thing1 (or) Thing2 with a year range], and if the first year value is greater than [this year + 14] I have to return [this year + 14], but only if the current year is an even year, otherwise I have to return [this year + 13].

The trouble I’m having is how to identify a year in the middle of a string that doesn’t follow a well defined pattern, other than the first part of the year range starts with a 4 digit year.

What is the best way for me to go about this? Could somebody suggest how I could approach a solution to this issue? Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T22:50:49+00:00Added an answer on May 17, 2026 at 10:50 pm

    This regex pattern would work nicely: \b(?<Year1>\d{4})(?:-(?<Year2>\d{2,4}))?\b

    Explanation:

    • \b: is a word-boundary to ensure we’re capturing the years entirely on their own and not as part of another word (i.e., no partial match) – this is used to anchor both ends of the pattern
    • (?<Year1>\d{4}): named capture group to match 4 digits
    • (-(?<Year2>\d{2,4}))?: this matches the - dash and then uses a named capture group for the 2nd year which matches 2-4 repeated digits since those years vary in length. The opening and closing parentheses groups this pattern together, and finally the trailing ? makes the entire group optional for cases where the second year doesn’t exist.

    Technically the \d{2,4} part accepts 07, 107, 2007. Obviously a 3 digit year is incorrect. I suggest you perform additional error checking to capture such scenarios. You could prevent it by changing it to \d{2}|\d{4} but then you would match Year1 and not Year2 and lose user input.

    Here’s the code:

    string[] inputs = { "Thing1 Thing2 S1", "Thing1 Thing2 2006-07 Series 6", "Thing1 Thing2 2006-2007 S12 RP", "Thing1 Thing2 2020-21 S6", "Thing1 Thing2 2022-2024 S12", "Thing1 Thing2 2024 Onwards" };
    string pattern = @"\b(?<Year1>\d{4})(-(?<Year2>\d{2,4}))?\b";
    Regex rx = new Regex(pattern);
    
    foreach (var input in inputs)
    {
        Match m = rx.Match(input);
        Console.WriteLine("{0}: {1}", m.Success, input);
        if (m.Success)
        {
            string year1 = m.Groups["Year1"].Value;
            string year2 = m.Groups["Year2"].Value;
            Console.WriteLine("Year1: {0}, Year2: {1}", year1, year2 == "" ? "N/A" : year2);
        }
        Console.WriteLine();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have made a tab bar iOS project, when I received the request to
I've submitted a change to an Open Source project on Github, and received code
I have been writing something to read a request stream (containing gzipped data) from
I am implementing a library module to serve as client for couchdb change notifications.
Received a strange error when using secure websockets in Safari with Webbit server. Error
I received an e-mail which contained a link that looked like it was to
I received a list of numbers in Custom format (Type: 000000) that represent military
I received a demand to correct a ASP website that have lots of functions
I received this error on following code.Is this + sign is not available in
I read about Change the delegate of MGTwitterEngine and don't really get it. I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.