|
-
May 15th, 2008, 09:13 AM
#1
Thread Starter
Member
[RESOLVED] [2005] RegEx help - One more time!
OK, with much help from this forum, reading online and tweaking I have been trying to build a regex to capture dates within broader strings. The following:
((0?[1-9]|1[0-2])(/|-)(0?[1-9]|[1-2][0-9]|3[0-1])(/|-)(19|20)?[0-9][0-9])|((JANUARY|FEBRUARY|MARCH|APRIL|MAY|JUNE|JULY|AUGUST|SEPTEMBER|OCTOBER|NOVEMBER|DECEMBER) +([1-2][0-9]|3[0-1]|0?[1-9]),? +(19|20)?[0-9][0-9])
works for d/m/yy(yy), d-m-yy(yy), and MONTH d(,) yy(yy)
I have tried to add one more grouping to capture:
day Month Year (e.g., 10 FEBRUARY 2002)
but have failed. Any help would be greatly appreaciated.
-
May 15th, 2008, 09:32 AM
#2
Addicted Member
Re: [2005] RegEx help - One more time!
Something along these lines?
([0-3]?\d\s*(JANUARY|FEBRUARY|MARCH|APRIL|MAY|JUNE|JULY|AUGUST|SEPTEMBER|OCTOBER|NOVEMBER|DECEMBER)\s*(19| 20)?[0-9][0-9])
IDE: Visual Studio 2008/2010 - C# | VB.Net
-
May 15th, 2008, 09:47 AM
#3
Thread Starter
Member
Re: [2005] RegEx help - One more time!
(Isorfir) If I put a | at the end of my regex and append yours, it does not capture dd MONTH yyyy. Your regex does work by itself (i.e., it will capture the appropriate string). I don't know exactly how regex works, but does the second grouping consume something that the third grouping (yours) then can't pick up? I just can't get them all to work together.
-
May 15th, 2008, 09:58 AM
#4
Addicted Member
Re: [2005] RegEx help - One more time!
I did what you said and mine seems to be working, see if it works for you.
((0?[1-9]|1[0-2])(/|-)(0?[1-9]|[1-2][0-9]|3[0-1])(/|-)(19|20)?[0-9][0-9])|((JANUARY|FEBRUARY|MARCH|APRIL|MAY|JUNE|JULY|AUGUST|SEPTEMBER|OCTOBER|NOVEMBER|DECEMBER) +([1-2][0-9]|3[0-1]|0?[1-9]),? +(19|20)?[0-9][0-9])|([0-3]?\d\s*(JANUARY|FEBRUARY|MARCH|APRIL|MAY|JUNE|JULY|AUGUST|SEPTEMBER|OCTOBER|NOVEMBER|DECEMBER)\s*(19| 20)?[0-9][0-9])
If it still doesn't work, show me the range of values you're trying to match.
IDE: Visual Studio 2008/2010 - C# | VB.Net
-
May 15th, 2008, 10:44 AM
#5
Thread Starter
Member
Re: [2005] RegEx help - One more time!
That worked - I wish I knew why! Thanks so much.
-
May 15th, 2008, 10:57 AM
#6
Addicted Member
Re: [2005] RegEx help - One more time!
As for yours not working, try looking to see what the differences were. I had to mess around with spacing and parenthesis.
A good website on RegEx is http://www.regular-expressions.info/
IDE: Visual Studio 2008/2010 - C# | VB.Net
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|