[OC]正規表現の簡単な適用

602 ワード

NSString * text = @"   #  #,@      @   ?http://www.baidu.com";
//\w                  
//    @             
NSString * regex = @"@\\w+";   //   @  ,@ 
//    #***#        
NSString * regex = @"#\\w+#"; //   #  #
//   url  
NSString * regex = @"http(s)?://([A-Za-z0-9._-]+(/)?)*"; //   http://www.baidu.com

//           
NSString * regex = @"(@\\w+)|(#\\w+#)|(http(s)?://([A-Za-z0-9._-]+(/)?)*)"

NSArray * array = [text coponentMatchedByRegex:regex];
for(NSString *s in array)
{
    NSLog(@"%@",s);
}

//