【发布时间】:2012-10-17 01:09:08
【问题描述】:
我很擅长使用 Objective-C 的正则表达式。我遇到了一些困难。
NSRegularExpression *regex = [NSRegularExpression regularExpressionWithPattern:@"\\b([1-9]+)\\b" options:NSRegularExpressionCaseInsensitive error:®Error];
if (regError) {
NSLog(@"%@",regError.localizedDescription);
}
__block NSString *foundModel = nil;
[regex enumerateMatchesInString:self.model options:kNilOptions range:NSMakeRange(0, [self.model length]) usingBlock:^(NSTextCheckingResult *match, NSMatchingFlags flags, BOOL *stop) {
foundModel = [self.model substringWithRange:[match rangeAtIndex:0]];
*stop = YES;
}];
我要做的就是获取一个类似的字符串
150A
得到
150
【问题讨论】:
标签: objective-c ios regex cocoa nsregularexpression