Tôi khá xanh ở regex với Objective-C. Tôi gặp khó khăn với nó.NSRegularExpressions mục tiêu-C, tìm sự xuất hiện đầu tiên của các số trong một chuỗi
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;
}];
Tất cả tôi đang tìm cách để làm là lấy một chuỗi như
150A
Và nhận
150
Rất hoàn hảo. Cảm ơn bạn! – rnystrom