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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T19:01:40+00:00 2026-05-11T19:01:40+00:00

Ok, i’m a regex doofus. I only ever learn enough to get me by,

  • 0

Ok, i’m a regex doofus. I only ever learn enough to get me by, but i would like to know how to do the below regex without using a php ternary operator in the middle of it. Also it may be ugly but it works…

'^". $date[0].(($date[0] == 0)?'?':'').$date[1]."[/.-]".$date[2].(($date[2] == 0)?'?':'').$date[3]."'";

uhm. as you can see im using a ternary operator to test if the date contains a 0. if it does.. then it can be ignored, if not then its a 1 or 2 and do not ignore. i’m sure there is a way to write this with just regex? If you know how then please tell me and i will be forever greatful. Also, just incase you wondering this is a regex in a mysql query.

  • 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-11T19:01:40+00:00Added an answer on May 11, 2026 at 7:01 pm

    Are you looking for this? match[1] is the month, match[2] is the day and match[3] is the year

    $regex = '#(0?[1-9]|1[0-2])[-/]([0-2]?[1-9]|3[01])[-/](19|20)?\d\d)#';
    

    You have a couple problems here.

    First, never ever put a text into a database that you haven’t made sure is formatted correctly. The fact that the dates are in the database with and without the 0’s is a problem. Why aren’t the dates in datetime fields where the database would make sure they are formatted correctly?

    Second, the regex above only works in the US where ‘mm/dd/yyyy’ dates are used. Support for other date formats is impossible if you are tied to that regex.

    Third, why are you doing this in the database? Your example is WHERE birthday regex something…. That means you have this date before you are passing it to mySQL. So fix the date in PHP first:

    $date = strtotime($_GET['date']);
    $sql = "select blah From blah WHERE birthday = '$date' blah";
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

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.