Ron,
A couple of thoughts.
This is the sort of expression that lends itself quite well to brute-force
testing. It's pretty easy for you to throw a whole mess of values at it
(even the whole Int32 range) to see how it behaves.
My general approach is not to do this kind of thing in regex, as it's so
tough to read and debug. It's much easier to do it in code.
If you do, here's my advice:
1) Download my regex tool from here:
http://www.gotdotnet.com/Community/...mpleGuid=C712F2DF-B026-4D58-8961-4EE2729D7322
2) Write your regexes like:
string pattern = @"
(
\d | # any single digit number
\d\d | # any two-digit number
1[01]\d # 10d or 11d
12[0-8] # 120 - 128
)
"
You'll need to use RegexOptions.IgnorePatternWhitespace
--
Eric Gunnerson
Visit the C# product team at
http://www.csharp.net
Eric's blog is at
http://weblogs.asp.net/ericgu/
This posting is provided "AS IS" with no warranties, and confers no rights.
Ron Rohrssen said:
Agreed!
I use regular expressions about once every 2 years. I still haven't
found
a
straight forward tutorial that doesn't take days to read through. I even
bought the O'Reilly Regular Expressions book when I was doing some Perl
several years ago. At the time I found it pretty useful. But like most
things, if you don't use it, you lose it.
Do you have any "favorite" sites or books that you like to use for
reference?
Ron
Jon Skeet said:
Yes, I see the overlap now. Thanks.
\b(12[0-8] | 1[0-1][0-9] | 0?[0-9]?[0-9])\b
What does the ? mean in your regex?
It's basically "the preceding character is optional".
I really wouldn't start messing around with regular expressions like
this without reading a thorough tutorial on it and having MSDN handy,
personally.