fork download
  1. #import <objc/objc.h>
  2. #import <objc/Object.h>
  3. #import <Foundation/Foundation.h>
  4.  
  5. int main()
  6. {
  7. NSString *searchedString = @"Some string @Vasya, hello, @Tolya! @,, sss@ssss";
  8. NSRange searchedRange = NSMakeRange(0, [searchedString length]);
  9. NSString *pattern = @"\\B@\\w\\S*\\b";
  10. NSError *error = nil;
  11.  
  12. NSRegularExpression* regex = [NSRegularExpression regularExpressionWithPattern: pattern options:0 error:&error];
  13. NSArray* matches = [regex matchesInString:searchedString options:0 range: searchedRange];
  14. for (NSTextCheckingResult* match in matches) {
  15. NSString* matchText = [searchedString substringWithRange:[match range]];
  16. for(int i = 0; i< match.numberOfRanges;i++)
  17. {
  18. NSRange group1 = [match rangeAtIndex:i];
  19. NSLog(@"group1: %@%lu", [searchedString substringWithRange:group1],group1.location);
  20. }
  21.  
  22. }
  23. return 0;
  24. }
  25.  
Success #stdin #stdout #stderr 0.03s 42896KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
2016-01-28 08:20:39.290 prog[5728] autorelease called without pool for object (0x83b34b0) of class NSRegularExpression in thread <NSThread: 0x8375800>
2016-01-28 08:20:39.291 prog[5728] autorelease called without pool for object (0x8410eb8) of class GSMutableArray in thread <NSThread: 0x8375800>
2016-01-28 08:20:39.291 prog[5728] autorelease called without pool for object (0x84117a8) of class GSRegularExpressionCheckingResult in thread <NSThread: 0x8375800>
2016-01-28 08:20:39.291 prog[5728] autorelease called without pool for object (0x83ddbe8) of class GSRegularExpressionCheckingResult in thread <NSThread: 0x8375800>
2016-01-28 08:20:39.291 prog[5728] autorelease called without pool for object (0x840b100) of class GSCInlineString in thread <NSThread: 0x8375800>
2016-01-28 08:20:39.291 prog[5728] autorelease called without pool for object (0x83d8228) of class GSCInlineString in thread <NSThread: 0x8375800>
2016-01-28 08:20:39.291 prog[5728] group1: @Vasya12
2016-01-28 08:20:39.291 prog[5728] autorelease called without pool for object (0x83d8bc0) of class GSCInlineString in thread <NSThread: 0x8375800>
2016-01-28 08:20:39.291 prog[5728] autorelease called without pool for object (0x83dd018) of class GSCInlineString in thread <NSThread: 0x8375800>
2016-01-28 08:20:39.292 prog[5728] group1: @Tolya27