Remove all non-numeric characters from an NSString, keeping spaces
I am trying to remove all of the non-numeric characters from an NSString , but I also need to keep the spaces. Here is what I have been using. NSString *strippedBbox = [_bbox stringByReplacingOccurrencesOfString:@"[^0-9]" withString:@"" options:NSRegularExpressionSearch range:NSMakeRange(0, [_bbox length])]; If I give it a NSString of Test 333 9599 999 It will return 3339599999 but I need to keep the spaces in. How can I do this? Easily done by creating a character set of characters you want to keep and using invertedSet to create an "all others" set. Then split the string into an array