Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/17.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
url IOS中的NSRegularExpression_Ios_Regex_Nsexpression - Fatal编程技术网

url IOS中的NSRegularExpression

url IOS中的NSRegularExpression,ios,regex,nsexpression,Ios,Regex,Nsexpression,我有一个从url获取标题的方法 它的工作,但在一个网站上,我没有比赛的结果 你知道问题出在哪里吗 网页上的标题是Test-sds NSURL *url_s = [NSURL URLWithString:url]; NSData* data = [NSData dataWithContentsOfURL:url_s]; if(data!=nil){ NSString* newStr = [NSString strin

我有一个从url获取标题的方法

它的工作,但在一个网站上,我没有比赛的结果

你知道问题出在哪里吗

网页上的标题是Test-sds

NSURL *url_s = [NSURL URLWithString:url];
            NSData* data = [NSData dataWithContentsOfURL:url_s];

            if(data!=nil){
                NSString* newStr = [NSString stringWithUTF8String:[data bytes]];
                NSRegularExpression *regex = [NSRegularExpression regularExpressionWithPattern:@"<title>(.*)</title>" options:0 error:NULL];

                NSTextCheckingResult *match = [regex firstMatchInString:newStr options:0 range:NSMakeRange(0, [newStr length])];

                NSString *title = [newStr substringWithRange:[match rangeAtIndex:1]];
}
NSURL*url_s=[NSURL-URLWithString:url];
NSData*data=[NSData data with contentsofURL:url\s];
如果(数据!=nil){
NSString*newStr=[NSString stringWithUTF8String:[数据字节]];
NSRegularExpression*regex=[NSRegularExpression regular expressionwithpattern:@“(.*)”选项:0错误:NULL];
NSTextCheckingResult*match=[regex firstMatchInString:newStr选项:0范围:NSMakeRange(0[newStr长度])];
NSString*title=[newStr substringWithRange:[match rangeAtIndex:1]];
}

根据模式匹配HTML时,应使用
nsregularexpressioncasesincensitive
nsregularexpressiondotmatcheslineseparator
选项

NSRegularExpressionOptions opts = NSRegularExpressionCaseInsensitive | NSRegularExpressionDotMatchesLineSeparators;
NSRegularExpression *regex = [NSRegularExpression regularExpressionWithPattern:@"<title>(.*)</title>"
                                                                       options:opts
                                                                         error:NULL];
NSRegularExpressionOptions opts=nsregularexpressioncase不敏感| nsregularexpressiondotmatcheslineseparator;
NSRegularExpression*regex=[NSRegularExpression regular expression with pattern:@”(.*)”
选项:选择
错误:NULL];

根据模式匹配HTML时,应使用
nsregularexpressioncasesincensitive
nsregularexpressiondotmatcheslineseparator
选项

NSRegularExpressionOptions opts = NSRegularExpressionCaseInsensitive | NSRegularExpressionDotMatchesLineSeparators;
NSRegularExpression *regex = [NSRegularExpression regularExpressionWithPattern:@"<title>(.*)</title>"
                                                                       options:opts
                                                                         error:NULL];
NSRegularExpressionOptions opts=nsregularexpressioncase不敏感| nsregularexpressiondotmatcheslineseparator;
NSRegularExpression*regex=[NSRegularExpression regular expression with pattern:@”(.*)”
选项:选择
错误:NULL];

根据模式匹配HTML时,应使用
nsregularexpressioncasesincensitive
nsregularexpressiondotmatcheslineseparator
选项

NSRegularExpressionOptions opts = NSRegularExpressionCaseInsensitive | NSRegularExpressionDotMatchesLineSeparators;
NSRegularExpression *regex = [NSRegularExpression regularExpressionWithPattern:@"<title>(.*)</title>"
                                                                       options:opts
                                                                         error:NULL];
NSRegularExpressionOptions opts=nsregularexpressioncase不敏感| nsregularexpressiondotmatcheslineseparator;
NSRegularExpression*regex=[NSRegularExpression regular expression with pattern:@”(.*)”
选项:选择
错误:NULL];

根据模式匹配HTML时,应使用
nsregularexpressioncasesincensitive
nsregularexpressiondotmatcheslineseparator
选项

NSRegularExpressionOptions opts = NSRegularExpressionCaseInsensitive | NSRegularExpressionDotMatchesLineSeparators;
NSRegularExpression *regex = [NSRegularExpression regularExpressionWithPattern:@"<title>(.*)</title>"
                                                                       options:opts
                                                                         error:NULL];
NSRegularExpressionOptions opts=nsregularexpressioncase不敏感| nsregularexpressiondotmatcheslineseparator;
NSRegularExpression*regex=[NSRegularExpression regular expression with pattern:@”(.*)”
选项:选择
错误:NULL];

您无法安全地从带有正则表达式的HTML或XML派生内容。XML和HTML是有状态的,因此它们实际上必须被解析为有状态的。例如,使用正则表达式将返回以下错误结果:

<html>
<head>
    <!--<title>Old Title</title>-->
    <title>New Title</title>
</head>
</html>

新标题

您应该选择HTML解析器并使用它。我以前在应用程序中成功使用过。

您无法安全地从HTML或带有正则表达式的XML中派生内容。XML和HTML是有状态的,因此它们实际上必须被解析为有状态的。例如,使用正则表达式将返回以下错误结果:

<html>
<head>
    <!--<title>Old Title</title>-->
    <title>New Title</title>
</head>
</html>

新标题

您应该选择HTML解析器并使用它。我以前在应用程序中成功使用过。

您无法安全地从HTML或带有正则表达式的XML中派生内容。XML和HTML是有状态的,因此它们实际上必须被解析为有状态的。例如,使用正则表达式将返回以下错误结果:

<html>
<head>
    <!--<title>Old Title</title>-->
    <title>New Title</title>
</head>
</html>

新标题

您应该选择HTML解析器并使用它。我以前在应用程序中成功使用过。

您无法安全地从HTML或带有正则表达式的XML中派生内容。XML和HTML是有状态的,因此它们实际上必须被解析为有状态的。例如,使用正则表达式将返回以下错误结果:

<html>
<head>
    <!--<title>Old Title</title>-->
    <title>New Title</title>
</head>
</html>

新标题

您应该选择HTML解析器并使用它。我以前成功地在应用程序中使用过。

我不知道问题出在哪里,但我看到一些HTML,人们会将字母大写。。。所以有可能有人把。。。。。这不会在常规表达式中返回结果,而不是将
0
传递到
regularExpressionWithPattern:options:error:
中的
options
参数,使用
nsregularexpressionCaseSensitive
。另外,
newStr
可以使用
[nsstringwithcontentsofURL:encoding:error:
分配。不需要将HTML读入NSData,然后转换成NSString。嗨,我发现了问题所在,但我需要好的解决方案。在这个标题是新行…我不知道问题是什么,但我看到一些HTML,人们将大写字母。。。所以有可能有人把。。。。。这不会在常规表达式中返回结果,而不是将
0
传递到
regularExpressionWithPattern:options:error:
中的
options
参数,使用
nsregularexpressionCaseSensitive
。另外,
newStr
可以使用
[nsstringwithcontentsofURL:encoding:error:
分配。不需要将HTML读入NSData,然后转换成NSString。嗨,我发现了问题所在,但我需要好的解决方案。在这个标题是新行…我不知道问题是什么,但我看到一些HTML,人们将大写字母。。。所以有可能有人把。。。。。这不会在常规表达式中返回结果i