2011-05-31 48 views
1

在iOS系統中存在,檢查,如果子在範圍

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

如果我想測試如果谷歌的//和/什麼是做到這一點的好辦法之間存在?

回答

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!"); 
} 
+0

似乎並沒有工作 – SuperString 2011-05-31 17:22:09

+0

還我不認爲這會工作,因爲它會匹配https://imcool.com/theresgooglehere/helloworld/ – SuperString 2011-05-31 17:31:27

+0

我固定的正則表達式的工作 – arclight 2011-05-31 17:34:19