I would use the second approach, as it seems more convenient than using regular expressions (although I admittedly am not very experienced with them). A.
Given the input string NSString* input , I would filter out non-numeric characters as follows:
NSCharacterSet* notNumbersSet = [[NSCharacterSet decimalDigitCharacterSet] invertedSet]; NSArray * wholeNumbers = [input componentsSeparatedByCharactersInSet:notNumbersSet];
Now loop through an array of integers:
for( NSString* numString in wholeNumbers ) { NSInteger num = [numString intValue];
source share