0
我有下面的代码调用网站并从页面中提取标题。工作正常,但它也提取新的行字符或选项卡。所以有时候串看起来像从网页中提取标题的正则表达式
\r\n\tSome WebSite | Official Company Website\r\n
public string GetPageTitle(string url)
{
string regex = @"(?<=<title.*>)([\s\S]*)(?=</title>)";
string source = this._client.DownloadString(url);
return Regex.Match(source, regex, RegexOptions.IgnoreCase).Value;
}
应该是什么正则表达式忽略\r\n
和\t
使用'String.Trim()'从你的字符串,其中包括标签和新的生产线的空白。将'.Trim();'添加到'.Value'。 –
可以尝试类减法https://msdn.microsoft.com/en-us/library/ms994330.aspx像'[\ S \ s - [\ r \ n \ t]]' – sln
如果您想将它集成到你的正则表达式可以试试这个'@“(?<=