Use a third-party tool RegexKitLite in iPhone development to implement regular expressions

Source: Internet
Author: User

IPhone DevelopmentUse third-party toolsRegexKitLiteImplementationRegular ExpressionIs the content of this article, aboutRegular ExpressionI have also touched on several methods. For details about the implementation, refer to the details in this article.

1. Go to RegexKitLite to download the class library. decompress it and there will be an example package and two files. The two files are actually used and added to the project.

2. Add libicucore. dylib frameworks to the project.

3. Now all nsstring objects can call the method in RegexKitLite.

 
 
  1. NSString *email = @”kkk@aaa.com”;  
  2.  
  3. [email isMatchedByRegex:@"\\b([a-zA-Z0-9%_.+\\-]+)@([a-zA-Z0-9.\\-]+?\\.[a-zA-Z]{2,6})\\b”]; 

Return YES, which indicates the email format. Note that RegexKitLite uses the regular expression slightly different from wiki.

 
 
  1. searchString = @”http://www.example.com:8080/index.html”;  
  2.  
  3. regexString  = @”\\bhttps?://[a-zA-Z0-9\\-.]+(?::(\\d+))?(?:(?:/[a-zA-Z0-9\\-._?,'+\\&%$=~*!():@\\\\]*)+)?”;  
  4.  
  5. NSInteger portInteger = [[searchString stringByMatching:regexString capture:1L] integerValue];  
  6.  
  7. NSLog(@”portInteger: ‘%ld’”, (long)portInteger);  
  8.  
  9. // 2008-10-15 08:52:52.500 host_port[8021:807] portInteger: ‘8080′ 

Take the http example in string.

Summary:IPhone DevelopmentUse third-party toolsRegexKitLiteImplementationRegular ExpressionI hope this article will help you!

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.