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|Janua ry|Feb|Feb ruary|Mar| March|Apr| April|May| May|Jun|Ju ne|Jul|Jul y|Aug|Augu st|Sep|Sep tember|Oct |October|N ov|Novembe r|Dec|Dece mber)|(?:3 [01]|[12][ 0-9]|0?[1- 9])[ \t]+(?:Jan|January|Feb|Feb ruary|Mar| March|Apr| April|May| May|Jun|Ju ne|Jul|Jul y|Aug|Augu st|Sep|Sep tember|Oct |October|N ov|Novembe r|Dec|Dece mber)
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
My regular expression for this is
(?:3[01]|[12][0-9]|0?[1-9]
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
(?:1[0-2]|0?[1-9])$
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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)
Thks Terry
(ozo, thks, but Terry answer is more complete as you can understand)
ASKER
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
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?
ASKER
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)
ASKER
Excellent! Now is Ok! Have a good day that in Portugal is 3.00 AM and go sleep!