dcy123
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    
    NSString *pattern = @"\\[\\w+\\]";
    NSString *str =@"[整单][123][微信][";

    NSRegularExpression *regx = [[NSRegularExpression alloc] initWithPattern:pattern
                                                                     options:NSRegularExpressionCaseInsensitive error:nil];
    // 查找匹配的字符串
    NSMutableArray *results = [[NSMutableArray alloc] init];
    NSRange searchRange = NSMakeRange(0, [str length]);
    
    [regx enumerateMatchesInString:str options:0 range:searchRange usingBlock:^(NSTextCheckingResult *result, NSMatchingFlags flags, BOOL *stop) {
        
        NSRange groupRange =  [result rangeAtIndex:0];
        NSString *match = [str substringWithRange:groupRange];
        [results addObject:match];
    }];
    NSLog(@"result = %@",results);

    
}

 

分类:

技术点:

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-09-17
  • 2022-02-07
  • 2022-12-23
猜你喜欢
  • 2021-11-23
  • 2021-11-22
  • 2021-11-30
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案