ios 정규 표현 식

2354 단어
  [ ]:          -->          
  [a-z]:      a-z,     a-z     
  [0-9]:      0-9,     0-9   
  \\d:  "\"    ,            ,      "\"
 ^:                      ,         [] ,
       []     
{}:    
{n,m}:    n ,    m 
{n,}    n ,     
{n}:  n 
$:   ¥                 

일반적인 정규 표현 식http://www.cnblogs.com/zxin/archive/2013/01/26/2877765.html
   1:  abc
   :  @"abc"
  
   2:      a~z,     0~9 -->[a-z][0-9]  [a-z]\d
   :   @"^[a-z]\\d"
  
   3:        ,        
   : ^[a-z][0-9]$
  
   4:        ,      4~9   
   : @"^[a-z][0-9]{4,9}"
  
   5:       [^0-9]
   : @"^[^0-9][0-9]$"
  
   6:QQ  
 1.    
 2.5~12 
 3.   0  
   : @"^[1-9][0-9]{4,11}$"
  
   7:      
 1. 13/15/17/18
 2.   11
   : @"^[1][3578][0-9]{9}$"
        //1.       
        let str = "a12345"
        //2.         :      ,     0-9    5-10 
        let pattern = "^[a-z][0-9]{4,9}$"
        //3.           
        /*
        var caseInsensitive: NSRegularExpression.Options { get } //      
         
        var allowCommentsAndWhitespace: NSRegularExpression.Options { get } //           
         
        var ignoreMetacharacters: NSRegularExpression.Options { get } //    pattern          :$\[]()+*^.|
         
        var dotMatchesLineSeparators: NSRegularExpression.Options { get } //   .       ,        .      
         
        var anchorsMatchLines: NSRegularExpression.Options { get } //$,^           
         
        var useUnixLineSeparators: NSRegularExpression.Options { get } //       
( , , \r ) var useUnicodeWordBoundaries: NSRegularExpression.Options { get } // Unicode TR#29 。( , ) */ let regex = try! NSRegularExpression(pattern: pattern, options: .caseInsensitive) // , //regex.firstMatch(in: str, options: .reportCompletion, range: NSMakeRange(0, str.characters.count)) // , let result = regex.matches(in: str, options: .reportCompletion, range: NSMakeRange(0, str.characters.count)) if result.count != 0 { print(" , \(result.count)") print(result[0]) }else { print(" ") }

좋은 웹페이지 즐겨찾기