Link to home
Start Free TrialLog in
Avatar of novreisb
novreisb

asked on

c# Regex Valid Dates (without following digits )

I am using Regex Magic but I cannot isolate the Valid Dates.
 My regular expression for this is
(?:3[01]|[12][0-9]|0?[1-9])[/.-](?:1[0-2]|0?[1-9])|(?:1[0-2]|0?[1-9])[/.-](?:Jan|January|Feb|February|Mar|March|Apr|April|May|May|Jun|June|Jul|July|Aug|August|Sep|September|Oct|October|Nov|November|Dec|December)|(?:3[01]|[12][0-9]|0?[1-9])[ \t]+(?:Jan|January|Feb|February|Mar|March|Apr|April|May|May|Jun|June|Jul|July|Aug|August|Sep|September|Oct|October|Nov|November|Dec|December)

This was enough for me if I had not the following issue

1.95 with my regex returns 1.9 but this is not valid date for me because has a digit following it. I think there is a way to prevent this but I cannot get there!
thks
Avatar of ozo
ozo
Flag of United States of America image

(?:1[0-2]|0?[1-9])$
ASKER CERTIFIED SOLUTION
Avatar of Terry Woods
Terry Woods
Flag of New Zealand image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of novreisb
novreisb

ASKER

Yes, it was not only the following digits but also the precedent ones.  it works perfect!
 Thks Terry
 (ozo, thks, but Terry answer is more complete as you can understand)
Sorry Terry, but the look behind not working! Can you try it?
It's only included for the dates with format:
123.10

If you have format:
123 October

Then you'll need a modified pattern. Is that the case you're talking about?

If not, then which case is failing?
123.10 is failing! I removed the <  in the (?!<\d)  and it works apparently!
Apologies; I got the < and ! the wrong way around. It's corrected here:
(?<!\d)(?:3[01]|[12][0-9]|0?[1-9])[/.-](?:1[0-2]|0?[1-9])(?!\d)|(?:1[0-2]|0?[1-9])[/.-](?:Jan|January|Feb|February|Mar|March|Apr|April|May|May|Jun|June|Jul|July|Aug|August|Sep|September|Oct|October|Nov|November|Dec|December)|(?:3[01]|[12][0-9]|0?[1-9])[ \t]+(?:Jan|January|Feb|February|Mar|March|Apr|April|May|May|Jun|June|Jul|July|Aug|August|Sep|September|Oct|October|Nov|November|Dec|December)

Open in new window

Excellent! Now is Ok! Have a good day that in Portugal is 3.00  AM and go sleep!