Nick,
I agree, I break down regular expressions, while I am developing them.
However: Once I am comfortable that they work, I then combine them, to
"simplify" the supporting code.
[color=blue]
> It's personal preference, really.[/color]
Is it? My concern is the manual looping you are adding unnecessary
complexity to the code, hence my question. Plus you might be adding possible
performance problems (evaluating multiple RegEx as opposed to a single
complex one). Either method may be causing increased GC pressure. How does
that saying go "robbing peter to pay paul", don't get me wrong, sometimes it
is "better" to write more complex supporting code to simplify the RegEx
verses more complex RegEx to simplify the code...
Also my concern (with both methods) is precedence, which is a problem I my
expression has with 2 & 4 digit years (it actually allows a 3 digit year).
Manually looping over individual expressions may cause an different
expression to be matched then a properly constructed group with alternation
(I am not inferring my expression is properly constructed!).
Also in this instance I would consider something like:
Const pattern1 As String = "a"
Const pattern2 As String = "b"
Const pattern3 As String = "c"
Const pattern As String = pattern1 & "|" & pattern2 & "|" & pattern3
Which easily allows you to define & maintain the patterns separately, then
gain the "simplicity" of combining the RegEx call... I would then structure
my Unit Tests such that I could easily identify if pattern1, pattern2 or
pattern3 was failing or working...
[color=blue]
> If all of your regular expressions are combined into one complicated
> expression, seperated by 'or' operators, and you make a mistake, it's that
> much harder to find and fix the mistak[/color]
Note: | is the alternation operator not the Or operator... As Or implies
combining (when applied to numbers & boolean), where | does not combine it
provides alternatives!
Just a thought
Jay
"Nick Malik [Microsoft]" <nickmalik@hotmail.nospam.com> wrote in message
news:Q3mBd.832700$8_6.744651@attbi_s04...[color=blue]
> Hi Jay,
>
> I break down regular expressions for the same reason I break down a
> complicated task into multiple calls to different methods: to make it
> easier
> to understand and debug.
>
> It's personal preference, really. A regular expression for matching one
> date format is not going to be all that trivial. The OP wants to match
> multiple date formats. Unless you are an expert at Regex, and most folks
> aren't, it will be fairly easy to make a mistake in one of them.
>
> If all of your regular expressions are combined into one complicated
> expression, seperated by 'or' operators, and you make a mistake, it's that
> much harder to find and fix the mistake.
>
> I'll take my chances with multiple individual expressions.
>
> --
> --- Nick Malik [Microsoft]
> MCSD, CFPS, Certified Scrummaster
>
http://blogs.msdn.com/nickmalik
>
> Disclaimer: Opinions expressed in this forum are my own, and not
> representative of my employer.
> I do not answer questions on behalf of my employer. I'm just a
> programmer helping programmers.
> --
> "Jay B. Harlow [MVP - Outlook]" <Jay_Harlow_MVP@msn.com> wrote in message
> news:uvBrwx37EHA.1264@TK2MSFTNGP12.phx.gbl...[color=green]
>> Nick,
>> Why have multiple regular expressions?
>>
>> Especially when the | operator (alternation construct) in RegEx allows
>> for[/color]
> a[color=green]
>> single expression to match multiple terms?
>>
>>[/color]
>
http://msdn.microsoft.com/library/de...Constructs.asp[color=green]
>>
>> In other words instead of:
>> Dim rx1 As New RegEx("a")
>> Dim rx2 As New RegEx("b")
>> Dim rx3 As New RegEx("c")
>>
>> You can use
>> Dim rx As New RegEx("a|b|c")
>>
>> Hope this helps
>> Jay
>>
>>
>>
>> "Nick Malik [Microsoft]" <nickmalik@hotmail.nospam.com> wrote in message
>> news:QRhBd.261831$5K2.65227@attbi_s03...[color=darkred]
>> > well, you could create multiple regular expression that will parse out[/color][/color]
> the[color=green][color=darkred]
>> > date/time string: one expression for each format.
>> > Then, when you get a source string, loop through each of your regular
>> > expressions until one of them picks up a date.
>> >
>> > --
>> > --- Nick Malik [Microsoft]
>> > MCSD, CFPS, Certified Scrummaster
>> >
http://blogs.msdn.com/nickmalik
>> >
>> > Disclaimer: Opinions expressed in this forum are my own, and not
>> > representative of my employer.
>> > I do not answer questions on behalf of my employer. I'm just a
>> > programmer helping programmers.
>> > --
>> > "Brian Mitchell" <MagellanTX@hotmail.com> wrote in message
>> > news:uCMmTcv7EHA.2012@TK2MSFTNGP15.phx.gbl...
>> >> Is there an easy way to pull a date/time stamp from a string? The
>> >> DateTime
>> >> stamp is located in different parts of each string and the DateTime[/color][/color]
> stamp[color=green][color=darkred]
>> >> could be in different formats (mm/dd/yy or dd/mm/yyyy, or hh:mm:ss
>> >> dd/mm...etc.)
>> >>
>> >> Any ideas would be appreciated,
>> >> Thanks!!
>> >>
>> >>
>> >
>> >[/color]
>>
>>[/color]
>
>[/color]