你能帮我制作正则表达式吗?在大字符串中,我需要找到这些子字符串(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,其语法与普通的objective c正则表达式相同。
最佳答案
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);
关于objective-c - 用于解析 html 的正则表达式;,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7903913/