Reputation: 738
I'm using a parser, which mistakenly parses IP addresses as double values. Since I know nothing about regular expressions, take a look:
AddRule<double>("!!float", @"[-+]?(0|[1-9][0-9_]*)\.[0-9_]*([eE][-+]?[0-9]+)?",
m => Convert.ToDouble(m.Value.Replace("_", "")), null);
AddRule<double>("!!float", @"[-+]?\._*[0-9][0-9_]*([eE][-+]?[0-9]+)?",
m => Convert.ToDouble(m.Value.Replace("_", "")), null);
AddRule<double>("!!float", @"[-+]?(0|[1-9][0-9_]*)([eE][-+]?[0-9]+)",
m => Convert.ToDouble(m.Value.Replace("_", "")), null);
Is there some quick way to fix that? (The error is on the first lambda expression)
Upvotes: 1
Views: 48
Reputation: 738
Alright, this does the trick.
AddRule<double>("!!float", @"^[0-9]*(?:\.[0-9]*)?$",
m => Convert.ToDouble(m.Value.Replace("_", "")), null);
Upvotes: 1