//???????????????????????????????
NSString *urlString = @"sfdshttp://www.baidu.com";
NSError *error;
//http+:[^\s]* ??????????????????
NSRegularExpression *regex = [NSRegularExpression regularExpressionWithPattern:@"http+:[^\s]*" options:0 error:&error];
if (regex != nil) {
NSTextCheckingResult *firstMatch = [regex firstMatchInString:urlString options:0 range:NSMakeRange(0?? [urlString length])];
if (firstMatch) {
NSRange resultRange = [firstMatch rangeAtIndex:0];
//??urlString?н??????
NSString *result = [urlString substringWithRange:resultRange];
NSLog(@"%@"??result);
}
}
?????????????
????[1302:403] http://www.baidu.com
??????????iOS??????????????????????????????????????
??????????????????????????÷???
????1.????NSPredicate??ν??????
?????????????Ч????
????NSString ??email ?? @“nijino_saki@163.com”??
????NSString *regex = @"[A-Z0-9a-z._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2??4}";
????NSPredicate *predicate = [NSPredicate predicateWithFormat:@"SELF MATCHES %@"?? regex];
????BOOL isValid = [predicate evaluateWithObject:email];
????ν???????????????????ν??????????
????2.????rangeOfString??option????????
????NSString *searchText = @"// Do any additional setup after loading the view?? typically from a nib.";
????NSRange range = [searchText rangeOfString:@"(?:[^??])*\." options:NSRegularExpressionSearch];
????if (range.location != NSNotFound) {
????NSLog(@"%@"?? [searchText substringWithRange:range]);
????}
????options???趨NSRegularExpressionSearch?????????????????????????????????λ?á?
????С??
?????????????????NSPredicate??д????????????????????????????????????????????????????????????????????????????????Σ?????????Ч???????