RegexKitLite 使用详解

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  
        若参数capture0L表示全部字符 --ishtml
        若参数capture1L表示正则表达式中第一个括号内匹配的字符(若不存在第一个括号,则argument is not valid程序崩溃)--is
        若参数capture2L表示正则表达式中第二个括号内匹配的字符(若不存在第二个括号,则argument is not valid程序崩溃)--ht
        若参数capture3L表示正则表达式中第三个括号内匹配的字符(若不存在第三个括号,则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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值