Solved

regex for 2011-2-3

Posted on 2012-03-11
11
222 Views
Last Modified: 2012-03-12
I tried /^\d{1,2}-\d{1,2}-\d{4}$/

but it fails.

I then tried /^\d{1,2}/-\d{1,2}/-\d{4}$/

also failed
0
Comment
Question by:bhomass
  • 4
  • 3
  • 3
  • +1
11 Comments
 
LVL 35

Accepted Solution

by:
Terry Woods earned 120 total points
ID: 37707974
Try:
/^\d{4}-\d{1,2}-\d{1,2}$/
0
 
LVL 14

Expert Comment

by:brendanmeyer
ID: 37707976
^\d{4}[/-]\d{1,2}[/-]\d{1,2}$
0
 
LVL 7

Expert Comment

by:micropc1
ID: 37707983
Maybe try something like...

/^[2][0][0-1][0-2][. /-][0-1][0-2][. /-][0-3][0-9]$/
0
 

Author Comment

by:bhomass
ID: 37708042
sorry, my bad. the problem was else where. I think my regex was good.
0
 

Author Comment

by:bhomass
ID: 37708066
I've requested that this question be closed as follows:

Accepted answer: 0 points for bhomass's comment #37708042

for the following reason:

bad question on my part.
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 35

Expert Comment

by:Terry Woods
ID: 37708067
I object to accepting your own comment as the solution. The date format as given in the question title was clearly different to what would match in your own patterns (yours expected the year at the end). Experts provided correct solutions to the given problem and they should be accepted.
0
 
LVL 7

Expert Comment

by:micropc1
ID: 37708127
I also object - adequate solutions were given. Looking at bhomass's past activity I'm seeing a pattern here...moderator might want to look at this...
0
 

Author Comment

by:bhomass
ID: 37708478
I wrote the wrong pattern. was doubly bad on my part. what I should have written was
What I meant to post was /^\d{4}-\d{1,2}-\d{1,2}$/. Same as what an experts suggested.

I could give you credit for that if you feel justified. But the problem I was having was not this one. I thought maybe the - character was what caused my problems, but it was not. I don't believe the [/-] modification was a good suggestion. Would you like to make a case that it was?

I would not go where I have pattern of anything. each post has its own history, and I have given credits whenever the experts had a valid case.
0
 
LVL 7

Expert Comment

by:micropc1
ID: 37709577
Yes - sorry. I see that I was mistaken and I retract my objection - have a good day.
0
 
LVL 35

Expert Comment

by:Terry Woods
ID: 37711983
I believe points are justified. 3 solutions were offered to the given problem - I recommend a split between them as you see fit.
0
 

Author Closing Comment

by:bhomass
ID: 37712042
not exactly the answer I was looking for. expert pointed a mis-typed expression. the real answer is it is ok to have the '-' char to represent itself in a regex expression
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Suggested Solutions

Article by: DanRollins
This article describes a JavaScript program that creates a maze made of hexagonal cells.  In Part 2 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7850-Hex-Maze-Part-2.html), we'll extend the program by adding a depth-…
The task A number given should be formatted for easy reading by separating digits into triads. Format must be made inline via JavaScript, i.e., frameworks / functions are not welcome. So let’s take a number like this “12345678.91¿ and format i…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now