[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" @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

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.