Regular Expressions (open-source framework)

Source: Internet
Author: User

    1. Open source implementations of regular expressions: Regexkitlite (non-ARC) Use this class and need to import a dependent library: Libicucore.dylib
    2. NSString *text = @ "Zhang San: 010-88669900, li 4,232 phone 010-55443322 send 0731-8373834 garbage fee";
    3. 1. Defining Regular Expressions
    4. NSString *regex = @ "\\d{3,4}-\\d{7,8}";
    5. 2. Create a regular Expression implementation object
    6. Nsregularexpression *expression = [[Nsregularexpression alloc] Initwithpattern:regex options: Nsregularexpressioncaseinsensitive Error:nil];
    7. 3. Expression finds a string that conforms to a regular expression
    8. Nsarray *items = [Expression matchesinstring:self options:nsmatchingreportprogress range:nsmakerange (0, Self.length)] ;
    9. Nsmutablearray *itemarray = [Nsmutablearray array];

10.//4. Looping through the found results

    1. For (Nstextcheckingresult *result in items) {
    2. The range of strings that conform to the expression
    3. Nsrange range = [Result range];
    4. NSString *matchstring = [self substringwithrange:range];
    5. [ItemArray addobject:matchstring];
    6. }
    7. Nsrange RG = [text Rangeofregex:regex];
    8. NSString *substring = [text Substringwithrange:rg];

Recommended Learning site: http://www.jb51.net/tools/zhengze.html

Regular Expressions (open-source framework)

Related Article

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.