objective-c - 用于解析 html 的正则表达式;

标签 objective-c ios regex facebook parsing

你能帮我制作正则表达式吗?在大字符串中,我需要找到这些子字符串(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/

相关文章:

regex - 从 bash 中的字符串中删除所有特殊字符和大小写

c# - 正则表达式在模拟器中有效,但在 C# 实现中失败。我缺少什么?

iOS isKindOfClass 和 isMemberOfClass 之间的区别

objective-c - cocoa 助手应用程序

iOS 应用程序 : running on simulator but not building the. 应用程序

如果 GPS 关闭,IOS 检查应用程序

ios - 在没有 Segue 的 UIViewController 之间移动

ios - 按钮总是在 xCode 中移动到中心

ios - 为什么 UIAElement 的 child 不等于自己?

regex - 捕获组引用 + 数字