fork(2) download
  1. #import <objc/objc.h>
  2. #import <objc/Object.h>
  3. #import <Foundation/Foundation.h>
  4.  
  5. @implementation TestObj
  6. int main()
  7. {
  8. NSString *pattern = @"^/api/v1/news/([0-9]+)/\\?categoryId=([0-9]+)$";
  9. NSString *string = @"/api/v1/news/123/?categoryId=22abc";
  10. NSError *error = nil;
  11. NSRegularExpression *regex = [NSRegularExpression regularExpressionWithPattern:pattern options:0 error:&error];
  12.  
  13. NSRange textRange = NSMakeRange(0, string.length);
  14. NSRange matchRange = [regex rangeOfFirstMatchInString:string options:NSMatchingReportProgress range:textRange];
  15.  
  16. // Did we find a matching range
  17. if (matchRange.location != NSNotFound)
  18. NSLog (@"YES! It is matched!");
  19. else
  20. NSLog (@"NO MATCH!");
  21. return 0;
  22. }
  23. @end
Success #stdin #stdout #stderr 0.03s 42880KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
2015-09-29 21:06:13.254 prog[9897] autorelease called without pool for object (0x88e44c0) of class NSRegularExpression in thread <NSThread: 0x88a6800>
2015-09-29 21:06:13.255 prog[9897] NO MATCH!