I would like to get a substring for a
You should be able to use NSRegularExpression to execute the same regex that you use in java. There is a good tutorial for NSRegularExpression here.
I was able to accomplish it with this code:
NSString *string = @"10% off with this item"; NSError *error = nil; NSRegularExpression *regex = [NSRegularExpression regularExpressionWithPattern:@"\\d+%" options:0 error:&error]; NSTextCheckingResult *result = [regex firstMatchInString:string options:0 range:NSMakeRange(0, [string length])]; NSString *substring = [string substringWithRange:result.range]; NSLog(@"%@", substring); // 10%
The key is in the TextCheckingResult. It contains the NSRange for the match in the original string so you can grab a substring of the match.