我有以下代码:
-(NSString*)getNumberFromString(NSString*)theString{
NSError *error = NULL;
NSRegularExpression *regex = [NSRegularExpression regularExpressionWithPattern:@"rhs: \"([0-9]*[.]*[0-9]*)" options:NSRegularExpressionCaseInsensitive | NSRegularExpressionAnchorsMatchLines error:&error];
NSArray *matches = [regex matchesInString:theString options:0 range:NSMakeRange(0, [theString length])];
NSTextCheckingResult *match = [matches objectAtIndex:0];
return [theString substringWithRange:[match rangeAtIndex:1]]);
}
当我尝试解析这个字符串时:
{lhs: "1 example", rhs: "44.5097254 Indian sample", error: "", icc: true}
我得到了结果44.5097254
。
但是对于这个字符串:
{lhs: "1 example", rhs: "44.5097254.00.124.2 sample", error: "", icc: true}
我得到一个不正确的结果44
。我期望得到44.5097254.00.124.2
.
我究竟做错了什么?