zoukankan      html  css  js  c++  java
  • iOS 正则表达式

    1.导入工程

    2.导入辅助库

    libicucore.tbd

    3.编译为非ARC        (-fno-objc-arc)

    4.定义正则表达式

    //用来匹配中文
            NSString * pattern=@"\[[\u4E00-\u9FA5]+\]";
     //待匹配字符串
            NSString * str=@"[哈哈]hello[你好]world[吗]good";

    5.引入头文件调用如下方法

    #import "RegexKitLite.h"
      //用来获取分割后的字符串
      [str enumerateStringsSeparatedByRegex:pattern usingBlock:^(NSInteger captureCount, NSString *const __unsafe_unretained *capturedStrings, const NSRange *capturedRanges, volatile BOOL *const stop) {
                NSLog(@"%@",*capturedStrings);
            }];
    //用来获取匹配的字符串 [str enumerateStringsMatchedByRegex:pattern usingBlock:^(NSInteger captureCount, NSString *const __unsafe_unretained *capturedStrings, const NSRange *capturedRanges, volatile BOOL *const stop) { NSLog(@"%@",*capturedStrings); }];

     

    //使用正则表达式做验证

        NSString *email = @"iMilo@163.com";

        NSString *regex = @"\b([a-zA-Z0-9%_.+\-]+)@([a-zA-Z0-9.\-]+?\.[a-zA-Z]{2,6})\b";   

       if ([email isMatchedByRegex:regex]){       

        NSLog(@"通过校验!");   

      }else{       

        NSLog(@"未通过校验,数据格式有误,请检查!");  

    }

    6.正则表达式详细网址: http://www.cnblogs.com/light169/archive/2006/10/18/532347.html

  • 相关阅读:
    vmware中的虚拟系统和真实系统同时上网
    code first实现自关联(树结构数据)
    td无内容如何显示边框
    vs新建模板
    为ashx文件启用session管理
    有效防止SQL注入漏洞
    用DIV建左右自动伸缩型布局
    身份证验证算法
    CSS布局需注意的问题
    使用sharppcap抓数据包
  • 原文地址:https://www.cnblogs.com/MrFeng/p/4980665.html
Copyright © 2011-2022 走看看