Created by LDW on 16/1/22.//copyright©2016 year LDW. All rights reserved.//#import <UIKit/UIKit.h> #import "ViewController.h" @interface Viewcontroller () @end @implem Entation Viewcontroller-(void) viewdidload {[Super viewdidload]; Use a regular expression with the class of the system (you can also use a third-party regexkitlite, of course)//1. Gets the string nsstring *user = @ "abc123def456kasdf999"; 2. Define regular Expressions (rules)//If our rule is "ABC" then the string is "Abcdsafasdfabcdsaf" then the 2 is found, plainly, the regular expression is to find something to use//here is assumed to find the number (the following string is the condition, specifically what to look for , you can surf the internet Baidu or see http://www.cnblogs.com/lidongxu/p/5153707.html) nsstring *patter = @ "[0-9]"; 3. Create nsregularexpression (call regular expression) (start at iOS4) nsregularexpression *regular = [[Nsregularexpression alloc] Initwithpattern: Patter options:0 Error:nil]; 4. Test the string (finally set which part of the test, here set the string user all) Nsarray *resultarr = [regular matchesinstring:user options:0 range:nsmakerange (0, user. Length)]; 5. Traverse result for (Nstextcheckingresult *result in Resultarr) {//print matching string in user's location NsloG (@ "%@", Nsstringfromrange (Result.range)); }} @end
[IOS] using regular expressions with system nsregularexpression