Ios 检查范围中是否存在子字符串

Ios 检查范围中是否存在子字符串,ios,Ios,在iOS中 如果我想测试google是否存在于//和/之间,那么什么是一个好方法?试试这个 Given an URL https://whateverthisisanurl.google.com/helloworld 我也不认为这会起作用,因为它会匹配,所以你想匹配没有跟在google后面或前面的字符串?那么正则表达式就是这个@“*?//.\\\。google\\…*?//.*?” NSString *mystring = @"https://whateverthisisanurl.googl

在iOS中

如果我想测试google是否存在于//和/之间,那么什么是一个好方法?

试试这个

Given an URL https://whateverthisisanurl.google.com/helloworld

我也不认为这会起作用,因为它会匹配,所以你想匹配没有跟在google后面或前面的字符串?那么正则表达式就是这个@“*?//.\\\。google\\…*?//.*?”
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!");
}