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 578921
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T14:18:42+00:00 2026-05-13T14:18:42+00:00

I shall test a date string to see if it is one of these

  • 0

I shall test a date string to see if it is one of these three:
dd-mm-yyyy OR yyyy OR dd-mm-yyyy/dd-mm-yyyy

I have combine these three, but the last one makes trouble since I cannot just match a single “/” using \Q/\E.

[0-9]{2}-[0-9]{2}-[0-9]{4}                                -> dd-mm-yyyy
[0-9]{4}                                                  -> yyyy
[0-9]{2}-[0-9]{2}-[0-9]{4}\Q/\E[0-9]{2}-[0-9]{2}-[0-9]{4} -> dd-mm-yyyy/dd-mm-yyyy

Combined they will give this expression:

([0-9]{2}-[0-9]{2}-[0-9]{4}|[0-9]{4}|[0-9]{2}-[0-9]{2}-[0-9]{4}\Q/\E[0-9]{2}-[0-9]{2}-[0-9]{4})

Question 1: How to only allow a single “/” between the dates?

Question 2: What does a ^ mean in the start of a regex and $ in the end? And should
I have it in mine

Br. Anders

UPDATE: (based on answers and comments below) Thanks! Two right answer. I marked the last one right since there also was a much smoother way to write what I had tried to do.

Language is probably XSLT or C#. It is in the CMS Umbraco that I place a regex to validate a default texstring/input field.

It acts a bit funny. There is no difference if I add a ^ to the start, therefore my question about that.

This string works perfekt: ^(?:\d{4}|\d{2}-\d{2}-\d{4}(?:/\d{2}-\d{2}-\d{4})?)$

  • 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-13T14:18:42+00:00Added an answer on May 13, 2026 at 2:18 pm

    Since you didn’t specify a language, I’ll suggest a working Perl version:

    /^(?:\d{4}|\d{2}-\d{2}-\d{4}(?:\/\d{2}-\d{2}-\d{4})?)$/
    

    Pattern explained:

    • start at the first character of the string
    • look for 4 digits ( \d{4} )
    • OR
    • a sequence of two digits dash two digits dash four digits
    • optionally a slash two digits dash two digits dash four digits
    • match the end of the string to make sure there is nothing else

    I quoted the literal / writing \/ as it’s the most cross-language way to do it: in Perl it would be enough to choose different pattern delimiter to avoid the need of escaping.

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

Sidebar

Related Questions

I wrote a small test program for flipperview. I have 3 views. I call
I have MANY small Test Projects where I put together just enough code to
Suppose I have several small test cases. Easy enough to setup and easy enough
I have small test app: Socket socket = new Socket(jeck.ru, 80); PrintWriter pw =
Work on this small test application to learn threading/locking. I have the following code,
i have build a small test app in Flash Pro 5.5 overlayed with the
I have finalized a small PHP application that can serve many documents. These documents
I have an XML document like this: <article> <author>Smith</author> <date>2011-10-10</date> <description>Article about <b>frobnitz</b>, crulps
I'm having a trouble making a form work. As I see it, everything is
I am currently writing a unit test framework which shall in the end run

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.