Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/26.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
html src regexp iOS_Ios_Objective C_Regex - Fatal编程技术网

html src regexp iOS

html src regexp iOS,ios,objective-c,regex,Ios,Objective C,Regex,需要一些关于这个简单regexp的提示 用于从中提取src的Regexp和目标字符串代码 现在,输出是意外的,因为它不仅返回组,还返回它之后直到结束标记的所有内容 输出 你的正则表达式太贪婪了 尝试: 你的正则表达式太贪婪了 尝试: 用于表达式。它基本上匹配了从第一个“到最后一个”的所有内容 您可能应该使用非贪婪运算符?,它是“.” 例如: 它基本上匹配了从第一个“到最后一个”的所有内容 您可能应该使用非贪婪运算符?,它是“.” 例如: NSString *imgTag = @"<img

需要一些关于这个简单regexp的提示

用于从中提取src的Regexp和目标字符串代码 现在,输出是意外的,因为它不仅返回组,还返回它之后直到结束标记的所有内容

输出
你的正则表达式太贪婪了

尝试:


你的正则表达式太贪婪了

尝试:


用于表达式。

它基本上匹配了从第一个
到最后一个
的所有内容

您可能应该使用非贪婪运算符
,它是“.”
例如:


它基本上匹配了从第一个
到最后一个
的所有内容

您可能应该使用非贪婪运算符
,它是“.”
例如:

NSString *imgTag = @"<img alt=\"\" src=\"/sites/default/files/mypic.gif\" style=\"width: 300px; height: 195px;\" />";

NSRegularExpression *a = [NSRegularExpression regularExpressionWithPattern:@"src=\"(.*)\"" options:NSRegularExpressionCaseInsensitive error:nil];
NSTextCheckingResult *matches = [a firstMatchInString:imgTag options:NSMatchingReportProgress range:NSMakeRange(0, [imgTag length])];

NSRange matchRange = [matches range];
NSString *src = [imgTag substringWithRange:matchRange];
NSLog(@"%s, %@", __PRETTY_FUNCTION__, src);
/sites/default/files/mypic.gif" style="width: 300px; height: 195px;
@"src=\"(.*?)\""
NSRegularExpression *a = [NSRegularExpression regularExpressionWithPattern:@"src=\"(.*?)\"" options:NSRegularExpressionCaseInsensitive error:nil];