ios html正则表达式,IOS使用正则表达式来找到ID在HTML

使用NSRegularExpression找到与40个字符的ID的出现在HTML

这里我的代码:

- (NSString *)stripOutHttp:(NSString *)string {

NSLog(@"the page content :: %@", string);

// Setup an NSError object to catch any failures

NSError *error = NULL;

// create the NSRegularExpression object and initialize it with a pattern

// the pattern will match any http or https url, with option case insensitive

//search for::

NSRegularExpression *regex = [NSRegularExpression regularExpressionWithPattern:@"

// try /\b([a-f0-9]{40})\b/

// create an NSRange object using our regex object for the first match in the string

NSRange rangeOfFirstMatch = [regex rangeOfFirstMatchInString:string options:0 range:NSMakeRange(0, [string length])];

// check that our NSRange object is not equal to range of NSNotFound

if (!NSEqualRanges(rangeOfFirstMatch, NSMakeRange(NSNotFound, 0))) {

// Since we know that we found a match, get the substring from the parent string by using our NSRange object

NSString *substringForFirstMatch = [string substringWithRange:rangeOfFirstMatch];

NSLog(@"Extracted data : %@",substringForFirstMatch);

// return the matching string

return substringForFirstMatch;

}

return NULL;

} 我目前正则表达式

所以:

NSRegularExpression *regex = [NSRegularExpression regularExpressionWithPattern:@"

我得到我所需要的部分:

Extracted data :

现在我该如何获得任何40个字符值的响应?

我试图与

// try /\b([a-f0-9]{40})\b/

但不似乎了解如何使用它,

这是::

非常感谢后的一种回应IM的

2012-12-19

MaKo

+2

用HTML解析器解析HTML。这会容易得多。 –

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值