开发者

checking if substring exist in range

开发者 https://www.devze.com 2023-03-09 07:06 出处:网络
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

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

精彩评论

暂无评论...
验证码 换一张
取 消