Results 1 to 6 of 6

Thread: [RESOLVED] [2005] RegEx help - One more time!

  1. #1

    Thread Starter
    Member
    Join Date
    Aug 2006
    Posts
    50

    Resolved [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.

  2. #2
    Addicted Member Isorfir's Avatar
    Join Date
    Feb 2006
    Location
    In Debug Mode
    Posts
    133

    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

  3. #3

    Thread Starter
    Member
    Join Date
    Aug 2006
    Posts
    50

    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.

  4. #4
    Addicted Member Isorfir's Avatar
    Join Date
    Feb 2006
    Location
    In Debug Mode
    Posts
    133

    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

  5. #5

    Thread Starter
    Member
    Join Date
    Aug 2006
    Posts
    50

    Re: [2005] RegEx help - One more time!

    That worked - I wish I knew why! Thanks so much.

  6. #6
    Addicted Member Isorfir's Avatar
    Join Date
    Feb 2006
    Location
    In Debug Mode
    Posts
    133

    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
  •  



Click Here to Expand Forum to Full Width