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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T00:04:37+00:00 2026-05-30T00:04:37+00:00

I want to know what the difference is between these two regular expressions, what

  • 0

I want to know what the difference is between these two regular expressions, what are the pro’s and con’s.

Example input (date) 31-12-2012.

Method A:
/(\d{2}-\d{2}-\d{4})/

And:

Method B:
^[0-9]{2}[-/][0-9]{2}[-/][0-9]{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-30T00:04:38+00:00Added an answer on May 30, 2026 at 12:04 am
    1. The first has delimiters /, the second one doesn’t. For now, I assume that to be a copy/paste issue.
    2. B forces a date to occur as the first item in the string with ^, A just agrees with "a datestring anyw00-00-0000where in the string".
    3. A captures the date in match 1 by the extra (), B does no such thing. As the entire match will be the 0th item in a match, you could lose the unneeded ()‘s.
    4. \d vs [0-9] -> see Avner’s answer.
    5. A only matches - as the day/month/year separator. Use that if you only expect -. If you expect BOTH - AND /, use [-/] as in B.
    6. B wants the the date to end in $, A doesn’t. Use the one which applies. If I assume this is a copy/paste error ($ being escaped because it is in a double quoted string for no good reason), it makes B match only a date because of the ^regex$ anchoring, and A a date string anywhere in the input. Once again, use the option that applies to your data.
    7. Neither of them validates a date. Only a format that kinda looks like one, but could as well not be one.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to know what the difference between these two foreignkey definitions are. (1)
I want to know the difference between these two statements.... ch=getch(); ch=(*getch)(); both statements
I want to know the difference between these two statements. Is one 'better' than
What is the difference between these two form submission methods? <form method=post action=gert.php onsubmit=return
i want to know the time difference between two countries. There is ofcourse the
I want to know the difference Between System.ApplicationException and System.Exception . Can anyone explain
I want to know the difference between : $this->forward(module, action); And $this->redirect(module/action); My first
I am a shell script newbie. I want to know the difference between ${var%pattern}
I am creating ASP.NET textbox controls dynamically. I want to know the difference between
I want to know the main difference between .live() vs. .bind() methods in jQuery.

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.