zoukankan      html  css  js  c++  java
  • iPhone中用第三方工具(RegexKitLite)实现正则表达

    1. 去RegexKitLite下 载类库,解压出来会有一个例子包及2个文件,其实用到的就这2个文件,添加到工程中。

    2.工程中添加libicucore.dylib frameworks。

    3.现在所有的nsstring对象就可以调用RegexKitLite中的方法了。

    NSString *email = @”kkk@aaa.com”;

    [email isMatchedByRegex:@"\\b([a-zA-Z0-9%_.+\\-]+)@([a-zA-Z0-9.\\-]+?\\.[a-zA-Z]{2,6})\\b”];

    返 回YES,证明是email格式,需要注意的是RegexKitLite用到的正则表达式和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′
    取 string中http的例子。

  • 相关阅读:
    java面向对象(五)之多态
    java集合(list,set,map)
    jQuery基础
    Numpy详解
    Pandas详解一
    Linux 解压缩
    Linux 磁盘挂载
    Linux 磁盘管理
    su和sudo命令详解
    Linux查看文件命令
  • 原文地址:https://www.cnblogs.com/lm3515/p/1962387.html
Copyright © 2011-2022 走看看