2

I am maintaining a program that uses TR1 regular expressions to evaluate user input for device settings. I have just switched the build environment for this program from visual studio 2008 to visual studio 2010. It was using the following regular expression to verify the form of an IP address:

^([0-9]{1,3})?(\.[0-9]{1,3}){0,3}$

The following is an example input that should have validated:

192.168.11.197

For some reason, under VS2010, this regular expression no longer validates a well formed IP address. I have resolved this problem by substituting this regular expression with the following (I found this on Regular expression to match DNS hostname or IP Address?:

^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$

My question is why does the former regular expression no longer work? I will admit to not being a master of the subtleties of regular expression ASCII art but had thought that I had an understandable solution.

Community
  • 1
  • 1
Jon Trauntvein
  • 4,453
  • 6
  • 39
  • 69
  • Can you provide some sample input that the first pattern failed on? – Asaph Dec 08 '10 at 14:46
  • Lots of bug fixes in VS2010's TR1 implementation, specifically for ``. Yes, don't expect it to work the same. – Hans Passant Dec 08 '10 at 15:22
  • 1
    An example of input that should have validated is now attached – Jon Trauntvein Dec 08 '10 at 15:53
  • 1
    if you're still monitoring at all... I wonder what you mean by "no longer validates" or "no longer work" - does that mean false positives? or false negatives? or that it doesn't compile? --- I could see why it would match a zero-length string, or why it would match an invalid IP like 987.987.789.789, but without knowing what failure you're having, I'm not sure how to answer your question. – Code Jockey Sep 19 '11 at 19:43
  • I mean that the regular expression was rejecting strings that it should have allowed. The syntax worked under vs2008 but stopped working under vs2010. – Jon Trauntvein Sep 21 '11 at 13:22
  • Just a comment. Your original regex wouldn't Validate an IP, it would optionally match an IP, as well as many other incorrect things that aren't IP's. It could actually be more simple, and will Validate correctly: ^(\d{1,3})(\.\d{1,3}){3}$ Granted, IP Validation has range modifiers which are best Validated using your second example. But according to your apparent needs, this would be better. – Suamere Apr 08 '13 at 18:34
  • 1
    Could you provide an example of how you are trying to implement this Regex in VS2010? – signus May 07 '14 at 17:57

0 Answers0