我有一些包含一些 img 标签的 html 数据,如下所示:
img width=500 height=400
img width=400 height=250
img width=600 height=470
高度和宽度总是在变化。我必须替换该html数据。我需要使用 Objective-C 将该 html 数据替换为“img with=100”。
我写了这些,但它不匹配
NSError *error = NULL;
NSRegularExpression *regex = [NSRegularExpression regularExpressionWithPattern:@"/(img\\s)((width|height)(=)([0-9]+)"
options:NSRegularExpressionCaseInsensitive
error:&error];
NSUInteger numberOfMatches = [regex numberOfMatchesInString:myhtmldata
options:0
range:NSMakeRange(0, [myhtmldata length])];
NSString *modifiedString;
if (numberOfMatches > 0)
{
modifiedString = [regex stringByReplacingMatchesInString:myhtmldata
options:0
range:NSMakeRange(0, [myhtmldata length])
withTemplate:@"img width=30"];
}
你能帮助我吗 ?