fork download
  1. #import <objc/objc.h>
  2. #import <objc/Object.h>
  3. #import <Foundation/Foundation.h>
  4. #import <Foundation/NSTextCheckingResult.h>
  5.  
  6. @implementation TestObj
  7. int main()
  8. {
  9. NSError *error = nil;
  10. NSString *pattern = @"(?:Name:\\s+Other\\s+Names\\s*|(?!^)\\G\\s*)Name:\\s+(\\w+)";
  11. NSString *string = @"Name: Tom\nName: Alex\nName: Karina\nName: Other Names\nName: Josh\nName: Sarah\nName: Mike";
  12. NSRange range = NSMakeRange(0, string.length);
  13. NSRegularExpression *regex = [NSRegularExpression regularExpressionWithPattern:pattern options:0 error:&error];
  14. NSArray *matches = [regex matchesInString:string options:0 range:range];
  15. for (NSTextCheckingResult* match in matches) {
  16. NSRange group1 = [match rangeAtIndex:1];
  17. NSPrint(@"%@", [string substringWithRange:group1]);
  18. }
  19. return 0;
  20. }
  21. void NSPrint(NSString *format, ...) {
  22. va_list args;
  23. va_start(args, format);
  24. NSString *string = [[NSString alloc] initWithFormat:format arguments:args];
  25. va_end(args);
  26. fprintf(stdout, "%s\n", [string UTF8String]);
  27. [string release];
  28. }
  29. @end
Success #stdin #stdout #stderr 0.04s 42896KB
stdin
Standard input is empty
stdout
Josh
Sarah
Mike
stderr
2016-04-28 07:15:26.179 prog[10589] autorelease called without pool for object (0x98014c0) of class NSRegularExpression in thread <NSThread: 0x97c3800>
2016-04-28 07:15:26.180 prog[10589] autorelease called without pool for object (0x985f2c0) of class GSMutableArray in thread <NSThread: 0x97c3800>
2016-04-28 07:15:26.181 prog[10589] autorelease called without pool for object (0x985fbb0) of class GSRegularExpressionCheckingResult in thread <NSThread: 0x97c3800>
2016-04-28 07:15:26.181 prog[10589] autorelease called without pool for object (0x982bfb8) of class GSRegularExpressionCheckingResult in thread <NSThread: 0x97c3800>
2016-04-28 07:15:26.181 prog[10589] autorelease called without pool for object (0x982fd38) of class GSRegularExpressionCheckingResult in thread <NSThread: 0x97c3800>
2016-04-28 07:15:26.181 prog[10589] autorelease called without pool for object (0x9801d10) of class GSCInlineString in thread <NSThread: 0x97c3800>
2016-04-28 07:15:26.181 prog[10589] autorelease called without pool for object (0x9828328) of class GSAutoreleasedMemory in thread <NSThread: 0x97c3800>
2016-04-28 07:15:26.181 prog[10589] autorelease called without pool for object (0x9859508) of class GSCInlineString in thread <NSThread: 0x97c3800>
2016-04-28 07:15:26.181 prog[10589] autorelease called without pool for object (0x98265e8) of class GSAutoreleasedMemory in thread <NSThread: 0x97c3800>
2016-04-28 07:15:26.181 prog[10589] autorelease called without pool for object (0x982fea8) of class GSCInlineString in thread <NSThread: 0x97c3800>
2016-04-28 07:15:26.181 prog[10589] autorelease called without pool for object (0x982bd50) of class GSAutoreleasedMemory in thread <NSThread: 0x97c3800>