Re: Regex question



I didn't say that finding date patterns was a lousy use of Regex. I said that trying to write such a complex Regex that it ensured it only matched valid dates (ie. did not match 99/99/9999) would be a lousy use. A blend of the two approaches is best - use Regex to get something that "looks" like a date and use DateTime to ensure it is valid.

You see this type of thing all the time when you see people write IP address or Email Address regex's. They go crazy trying to make it RFC compliant or ensure that it won't match anything invalid. But the regex quickly becomes unreadable and actually much slower than parsing.

So in summary - a simple regex gets you most of the way there and a parse confirms the validity. Sounds like you've got it working the way you want.

Good luck! Merry Christmas and Happy New Year!

Josh Einstein

"tshad" <tfs@xxxxxxxxxxxxxx> wrote in message news:u6lieXeaJHA.880@xxxxxxxxxxxxxxxxxxxxxxx

Regex will help you get most of the way there but trying to construct a pattern that will ensure a valid date within the range allowed by T-SQL would be a really lousy use of Regex in the first place.

I know know why it is a lousy use of it. Seems like a better way to find a date pattern in my text field then trying to parse the field with for/loops to find a date.

Thanks,



.



Relevant Pages

  • Re: Regex question
    ... that trying to write such a complex Regex that it ensured it only matched ... valid dates would be a lousy use. ... pattern that will ensure a valid date within the range allowed by T-SQL ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Regex doubt
    ... > really dont want to use HtmlAgilitypack - I'm learning RegEx and want to ... >>> exp is braindead as it chokes on nested tags. ... >>> says something like - 'match any text that doesnt match this ... >>>, within a pattern, match the pattern itself?In that case, the first ...
    (microsoft.public.dotnet.framework)
  • Re: string.remove bringt nicht das erwartete
    ... Ein Regex ist da etwas flexibler. ... pattern, "", System.Text.RegularExpressions.RegexOptions.IgnoreCase) ... Wenn man nun aber nach einem Backslash sucht ... gleichen gilt für alle anderen Metazeichen. ...
    (microsoft.public.de.german.entwickler.dotnet.vb)
  • Re: limits on regex?
    ... Same regex could work and fail on 2 different strings. ... not on the complexity of regex expression. ... storing / changing documents in DB and keep resulting pattern description ... > Does anyone have any hard data on the size / complexity limits of the ...
    (microsoft.public.dotnet.framework)
  • Parsing and regex
    ... I am writing a program to parse a Cisco ASA log file. ... I have created a database that contains the 6 ... digit rule number which is unique, a severity level, the full ASA rule ... regex "rule" in the database. ...
    (comp.lang.perl.misc)