私はObjective-Cで正規表現でかなり緑です。私はそれにいくつかの困難を抱えています。Objective-C NSRegularExpressionsは、文字列内の数字の最初の出現を見つけます。
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
完璧です。ありがとうございました! – rnystrom