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

  • 相关阅读:
    VS2012开发调试PHP扩展
    Android webapi
    拖动上传文件
    IE11被识别为mozilla
    jquery validate.js 不能验证
    如何安装或卸载 Internet Explorer 9?
    C# 操作IIS -App & AppPools
    Filewatcher
    Notepad++使用技巧
    u-boot-2012.04.01移植笔记——支持NAND启动
  • 原文地址:https://www.cnblogs.com/MrFeng/p/4980665.html
Copyright © 2011-2022 走看看