你能帮我制作RegExp吗?在大字符串中我需要找到这些子串(2种格式):
HTTP://www.facebook.com/profile.php ID = 100002234024152&安培; REF = FFA \ HTTP://www.facebook.com/alesya.yuldasheva REF = FFA \
我试过这些:
@"\\b(https?):\/\/www.facebook.com([.]{*})ref=ffa";
@"[{http:\/\/www.facebook.com}([.]{*}){ref=ffa}]";
@"[http:\/\/www.facebook.com]([.])*[ref=ffa]";
我使用RegexKitLite,其语法与普通目标c正则表达式相同。
答案 0 :(得分:1)
NSError *error = nil;
NSString *htmlAdr = [NSString stringWithContentsOfURL:[NSURL URLWithString:@"http://www.example.com"] encoding:NSUTF8StringEncoding error:&error];
if (error){
NSLog(@"Yaz");
}
// NSLog(@"%@", htmlAdr);
NSString *wereWeAreGoingToFind = htmlAdr;
NSString *whatWewAreGoingToFind1 = @"\\bhttps?:\\\\/\\\\/[a-zA-Z0-9\\-.]*\\\\/profile.php\\?id=([\\d]*)\\&ref=ffa";
NSString *whatWewAreGoingToFind = @"\\bhttps?:\\\\/\\\\/[a-zA-Z0-9\\-.]*\\\\/([a-zA-Z0-9\\-.]*)\\?ref=pb";
NSArray *matchArray = [wereWeAreGoingToFind componentsMatchedByRegex:whatWewAreGoingToFind capture:1L];
NSArray *matchArray1 = [wereWeAreGoingToFind componentsMatchedByRegex:whatWewAreGoingToFind1 capture:1L];
matchArray = [matchArray arrayByAddingObjectsFromArray:matchArray1];
NSLog(@"%@", matchArray);
答案 1 :(得分:0)
答案 2 :(得分:0)
看起来你需要逃避'。'在网址中也是如此。例如:
@ “(?HTTPS):(?*)\ b // WWW \ .facebook \的.com / REF = FFA”;