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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T08:22:25+00:00 2026-05-12T08:22:25+00:00

I have a solution for my question, but I’m trying to get better at

  • 0

I have a solution for my question, but I’m trying to get better at regex especially in javascript. I just wanted to bring this to the community to see if I could write this in a better way.

So, I get a datetime string that comes from .net and I need to extract the date from it.

Currently what I have is:

var time = "2009-07-05T00:00:00.0000000-05:00".match(/(^\d{4}).(\d{2}).(\d{2})/i);

As I said, this works, but I was hoping to make it more direct to only grab the Year, month, day in the array. What I get with this is 4 results with the first being YYYY-MM-DD, YYYY, MM, DD.

Essentially I just want the 3 results returned, not so much that this doesn’t work (because I can just ignore the first index in the array), but so that I can learn to use regex a bit better.

  • 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-12T08:22:25+00:00Added an answer on May 12, 2026 at 8:22 am

    Anytime you have parenthesis in your regex, the value that matches those parenthesis will be returned as well.

    • time[0] is what matches the whole expression
    • time[1] is what matches ([\d]{4}), i.e. the year
    • time[2] is what matches the first ([\d]{2}), i.e. the month
    • time[3] is what matches the second ([\d]{2}), i.e. the date

    You can’t change this behavior to remove time[0], and you don’t really want to (since the underlying code is already generating it, removing it wouldn’t give any performance benefit).

    If you don’t care about getting back the value from a parenthesized expression, you can use (?:expression) to make it non-matching.

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

Sidebar

Related Questions

I used the mapping solution from this question to have a joined component. But
Rather noobish question but I have tried searching and just cannot find a solution.
This actually corresponds to my other question but things get more complicated. I have
This may be a simple C# question but I need a solution. I have
This is may be old question but i dont get proper solution if it
Probably a long question for a simple solution, but here goes... I have a
Intro: EDIT: See solution at the bottom of this question (c++) I have a
This might be a silly question but I am still learning. I have read
This may be a silly question but... Say you have a sentence like: The
This might be a stupid question but I have spent 2 hours looking for

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.