[IOS] using regular expressions with system nsregularexpression

Source: Internet
Author: User
Tags uikit

//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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.