In iOS,
开发者_开发百科Given an URL https://whateverthisisanurl.google.com/helloworld
If I want to test if google exists between the // and / whats is a good way to do it?
Try this
NSString *mystring = @"https://whateverthisisanurl.google.com/helloworld";
NSString *regex = @".*?//.*?\\.google\\..*?/.*?";
NSPredicate *regextest = [NSPredicate
predicateWithFormat:@"SELF MATCHES %@", regex];
if ([regextest evaluateWithObject:mystring] == YES) {
NSLog(@"Match!");
} else {
NSLog(@"No match!");
}
精彩评论