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

  • 相关阅读:
    MySQL之视图
    C# 学习笔记(二) 时间格式化字符串
    C# 学习笔记(一) Winform利用Assembly反射动态创建窗体
    puppet 4.4 System Requirements
    Linux下MySql启动时报错
    Linux Iptables
    Nginx Configure时配置
    Wireshark 使用教程
    Linux 下安装oracle数据库
    CaseFile
  • 原文地址:https://www.cnblogs.com/MrFeng/p/4980665.html
Copyright © 2011-2022 走看看