本文介绍了在的NSString搜索与特定文字和结尾加上一个&QUOT开头的单词;的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个包含网页的HTML code一的NSString。
现在,我如何搜索的整个字符串为所有开头写着数据SRC =HTTP://,结束了?
我将它们保存在一个数组。
我的字符串被称为urlPage
I have a NSString that contains the html code of a webpage.Now, how do i search on the whole string for all the words that start with 'data-src="http://' and end with a " ?I'll save them in an array.My string is called urlPage
PS:我不想要的话有数据SRC =HTTP://和。我只是想的话这2
PS: i dont want the words to have the 'data-src="http://' and " . I just want the words between these 2
推荐答案
下面是一些例子code:
Here is some example code:
NSString *string;
NSString *pattern;
NSRegularExpression *regex;
string = @" aa data-src=\"http://test1\" cd data-src=\"http://test2\" cd";
pattern = @"data-src=\"http://([^\"]+)\"";
regex = [NSRegularExpression
regularExpressionWithPattern:pattern
options:NSRegularExpressionCaseInsensitive
error:nil];
NSArray *matches = [regex matchesInString:string
options:0
range:NSMakeRange(0, [string length])];
for (NSTextCheckingResult *match in matches) {
NSRange range = [match rangeAtIndex:1];
NSLog(@"match: '%@'", [string substringWithRange:range]);
}
的NSLog输出:结果
匹配:'TEST1'结果
比赛:test2的
NSLog output:
match: 'test1'
match: 'test2'
这篇关于在的NSString搜索与特定文字和结尾加上一个&QUOT开头的单词;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!