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.
- NSString *email = @”kkk@aaa.com”;
-
- [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.
- searchString = @”http://www.example.com:8080/index.html”;
-
- regexString = @”\\bhttps?://[a-zA-Z0-9\\-.]+(?::(\\d+))?(?:(?:/[a-zA-Z0-9\\-._?,'+\\&%$=~*!():@\\\\]*)+)?”;
-
- NSInteger portInteger = [[searchString stringByMatching:regexString capture:1L] integerValue];
-
- NSLog(@”portInteger: ‘%ld’”, (long)portInteger);
-
- // 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!