在iOS中,
Given an URL https://whateverthisisanurl.google.com/helloworld
如果我想测试//和/ whats之间是否存在google是一种很好的方法吗?
答案 0 :(得分:3)
试试这个
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!");
}