RegexKitLite 使用详解
2017-02-14 17:37
281 查看
1.匹配字符,并通过参数删选匹配字符
- (NSString *)RKL_METHOD_PREPEND(stringByMatching):(NSString*)regex capture:(NSInteger)capture;
NSString* searchString1 = @"http://www.e//isxample.com:80222080/http//isindex.ishtml";
NSString* regexString1 = @"(is)(ht)(ml)";
NSLog(@"portInteger: '%@'", [searchString1stringByMatching:regexString1capture:3L]
);
/*
匹配字符 : ishtml
若参数capture:0L表示全部字符 --ishtml
若参数capture:1L表示正则表达式中第一个括号内匹配的字符(若不存在第一个括号,则argument is not valid程序崩溃)--is
若参数capture:2L表示正则表达式中第二个括号内匹配的字符(若不存在第二个括号,则argument is not valid程序崩溃)--ht
若参数capture:3L表示正则表达式中第三个括号内匹配的字符(若不存在第三个括号,则argument is not valid程序崩溃)
-- ml
*/
NSString *searchString = @"<p>\r<img src=\"http://192.168.0.180/mobilemobile/UpFile/20140804134426.jpg\" /></p>\r<p>\r<span id=\"LabHome\">The
information contained in this Manual cover all the services you need to participate successfully in the Exhibition. It provides you with all the necessary information on Exhibition Services and Order Forms to ensure a smooth <img src=\"http://192.168.0.180/mobilemobile/UpFile/14758.gif\"
/>and trouble-free run-up to MEDICAL MANUFACTURING ASIA 2014.</span></p>";
NSString *regexString = @"<img src=\"[^>]*\" />";
// 将匹配后的字符存放于数组当中
NSArray *matchArray = [searchString componentsMatchedByRegex:regexString];
NSLog(@"%@",matchArray);
// 将匹配后的字符替换成指定字符
NSString* matchString = [searchString stringByReplacingOccurrencesOfRegex:regexStringwithString:@"||================||"];
NSLog(@"%@",matchString);
NSString* searchString1 =@"http://www.e//isxample.com:80222080/http//isindex.ishtml";
NSString* regexString1 = @"(isi)(ndex)";
NSLog(@"%@",[searchString1 componentsMatchedByRegex:regexString1]);
NSLog(@"%@",[searchString1 captureComponentsMatchedByRegex:regexString1]);
参考博文:http://blog.csdn.NET/ios_long/article/details/6720650
- (NSString *)RKL_METHOD_PREPEND(stringByMatching):(NSString*)regex capture:(NSInteger)capture;
NSString* searchString1 = @"http://www.e//isxample.com:80222080/http//isindex.ishtml";
NSString* regexString1 = @"(is)(ht)(ml)";
NSLog(@"portInteger: '%@'", [searchString1stringByMatching:regexString1capture:3L]
);
/*
匹配字符 : ishtml
若参数capture:0L表示全部字符 --ishtml
若参数capture:1L表示正则表达式中第一个括号内匹配的字符(若不存在第一个括号,则argument is not valid程序崩溃)--is
若参数capture:2L表示正则表达式中第二个括号内匹配的字符(若不存在第二个括号,则argument is not valid程序崩溃)--ht
若参数capture:3L表示正则表达式中第三个括号内匹配的字符(若不存在第三个括号,则argument is not valid程序崩溃)
-- ml
*/
NSString *searchString = @"<p>\r<img src=\"http://192.168.0.180/mobilemobile/UpFile/20140804134426.jpg\" /></p>\r<p>\r<span id=\"LabHome\">The
information contained in this Manual cover all the services you need to participate successfully in the Exhibition. It provides you with all the necessary information on Exhibition Services and Order Forms to ensure a smooth <img src=\"http://192.168.0.180/mobilemobile/UpFile/14758.gif\"
/>and trouble-free run-up to MEDICAL MANUFACTURING ASIA 2014.</span></p>";
NSString *regexString = @"<img src=\"[^>]*\" />";
// 将匹配后的字符存放于数组当中
NSArray *matchArray = [searchString componentsMatchedByRegex:regexString];
NSLog(@"%@",matchArray);
// 将匹配后的字符替换成指定字符
NSString* matchString = [searchString stringByReplacingOccurrencesOfRegex:regexStringwithString:@"||================||"];
NSLog(@"%@",matchString);
NSString* searchString1 =@"http://www.e//isxample.com:80222080/http//isindex.ishtml";
NSString* regexString1 = @"(isi)(ndex)";
NSLog(@"%@",[searchString1 componentsMatchedByRegex:regexString1]);
NSLog(@"%@",[searchString1 captureComponentsMatchedByRegex:regexString1]);
参考博文:http://blog.csdn.NET/ios_long/article/details/6720650
相关文章推荐
- RegexKitLite 使用详解
- iphone中使用第三方工具(RegexKitLite)实现正则表达式
- iOS中使用RegexKitLite来试用正则表达式 使用ARC 20个错误解决办法
- iOS中使用RegexKitLite来试用正则表达式 使用ARC 20个错误解决办法
- [iphone]使用(RegexKitLite)实现正则表达式 [转]
- [iphone]使用RegexKitLite实现正则表达式
- iOS中使用RegexKitLite来试用正则表达式
- IOS使用第三方工具(RegexKitLite)实现正则表达式小结
- RegexKitLite的使用
- [iphone]使用(RegexKitLite)实现正则表达式 [转]
- iphone中使用第三方工具(RegexKitLite)实现正则表达式
- iphone中使用第三方工具(RegexKitLite)实现正则表达式
- iOS中使用RegexKitLite来试用正则表达式
- iOS中使用RegexKitLite来试用正则表达式
- iOS中使用RegexKitLite来试用正则表达式
- [iphone]使用(RegexKitLite)实现正则表达式 [转]
- 使用RegexKitLite使iphone也可以使用正则表达式
- iOS中使用RegexKitLite来试用正则表达式 使用ARC 20个错误解决办法 mark
- iOS中使用RegexKitLite来试用正则表达式
- iphone中使用第三方工具(RegexKitLite)实现正则表达式