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

  • SEARCH
  • Home
  • 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 6364507
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T00:10:20+00:00 2026-05-25T00:10:20+00:00

My problem is as follows: I have an array of strings that contain dates

  • 0

My problem is as follows:

I have an array of strings that contain dates and other data. My date will have one of several formats:

  1. dd/mm/yyyy
  2. dd/mm/yy
  3. mm/yy
  4. d/m/yy
  5. yyyy
  6. yy

Is there a way to search a string for numbers that fit that pattern in the string?

In addition, it would be nice if I could check if the dd is between 1 and 31 inclusive etc, but it would not be so bad if I had to do that afterwards.

  • 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-25T00:10:21+00:00Added an answer on May 25, 2026 at 12:10 am

    Each of these corresponds to a regex.

    Here are regexes for each:

    • dd/mm/yyyy ==> \b(?:[012][1-9]|3[01])/(?:0[1-9]|1[012])/\d{4}\b
    • dd/mm/yy ==> \b(?:[012][1-9]|3[01])/(?:0[1-9]|1[012])/\d{2}\b
    • mm/yy ==> \b(?:0[1-9]|1[012])/\d\d\b
    • d/m/yy ==> \b[1-9]/[1-9]/\d\d\b
    • yyyy ==> \b\d{4}\b
    • yy ==> \b\d\d\b

    Of course, you can combine these together in different ways. You can even make one super regex.

    The last one is rather interesting, though. I can imagine a case where you might have a plain old number in your text, like 42 that might not actually correspond to a year. Still I guess you can postprocess that.

    Happy regexing.

    ADDENDUM

    To answer some questions in the comments:

    1. Yes it works at the beginning and the end of the string, because \b is a word boundary, which includes all transitions from word characters (letters, digits, and underscores) to non-word characters and vice-versa, including the beginning and ending of the string.

    2. To see tests, see here: http://jsfiddle.net/wRufK/. Yes I know this is in JavaScript and not C#, but jsfiddle is a very convenient way to show code in action. There are differences though — in C# we use Regex.match and the JavaScript regex has extra backslashes to escape the inner forward slashes.

    3. indexOf might be overkill depending on the application. If you want to find all matches, see http://msdn.microsoft.com/en-us/library/twcw2f1c.aspx for info on repeated matching. You can also modify the regexes for capturing.

    4. Since your dates can be in any of the forms above, and probably others, a single regex might be preferable. A very flexible date finder is here: http://www.regular-expressions.info/dates.html. You might want to consider it instead of fixing an exact set.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an array of strings that contain html <object> 's like so: $str
I have a table say, ITEM, in MySQL that stores data as follows: ID
I have a mysql problem, my query looks as follows but not complete SELECT
Problem 2b goes as follows: 2b. For each subject show the first year that
When I write a C program, I encountered a problem that is as follows:
I have simplified an issue that I've been having trying to isolate the problem,
I have a continous ajax request asking for some data that is to be
I have the very common problem of creating an index for an in-disk array
I have a 2D-array that I want to sort based on the second column.
I have a problem which has an solution that can be solved by iteration,

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.