开发者

checking if substring exist in range

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜