//Created by LDW on 16/1/22.//copyright©2016 year LDW. All rights reserved.// #import<UIKit/UIKit.h>#import "ViewController.h" @interfaceViewcontroller ()@end @implementationViewcontroller- (void) viewdidload {[Super viewdidload]; //Use regular expressions with system classes (of course you can also use a third-party regexkitlite this class)//1. Get the stringNSString*user =@"abc123def456kasdf999"; //2. Defining regular Expressions (rules)//If our rule is "ABC" then the string is "Abcdsafasdfabcdsaf" then we find 2, so to speak, regular expressions are for things.//This assumes that finding numbersNSString*patter =@"[0-9]"; //3. Create nsregularexpression (call regular expression) (start at iOS4)nsregularexpression*regular = [[Nsregularexpression alloc] initwithpattern:patter options:0Error:nil]; //4. Test the string (last set which part of the test, here set the string user all)Nsarray*resultarr = [Regular Matchesinstring:user options:0Range:nsmakerange (0, User.length)]; //5. Traverse the results for(Nstextcheckingresult *resultinchResultarr) { //prints the matching string in the user's locationNSLog (@"%@", Nsstringfromrange (Result.range)); } } @end
[IOS] using regular expressions with system nsregularexpression