将HTML代码与字符串模式匹配? [英] Match html code with string pattern?
本文介绍了将HTML代码与字符串模式匹配?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
你好,
如何用"string pattern =匹配HTML代码?
Hello,
How to match html code with "string pattern="?
string url = "http://nbt.tj/ru/kurs/?c=4&id=28&lg=ru&d=";
string pattern = "<td width="180" id="k_kurs">1 USD 4.7543</td>";
Match match = Regex.Match(html, pattern);
label2.Content = match.Groups[0].ToString();
谢谢.
Thank you.
推荐答案
使用WebClient.DownloadString
从相应的URL下载HTML.
请查看下面的链接,以获取有关WebClient.DownloadString
的更多信息.
http://msdn.microsoft.com/en-us/library/fhd1f0sw%28v = VS.100%29.aspx
这是几个有关" Regex "的信息的链接.
http://msdn.microsoft.com/en-us/library/system. text.regularexpressions.regex.aspx
30分钟正则表达式教程
UseWebClient.DownloadString
to download HTML from corresponding url.
Have a look at below link for more information onWebClient.DownloadString
.
http://msdn.microsoft.com/en-us/library/fhd1f0sw%28v=VS.100%29.aspx
Here are couple of links for information on "Regex".
http://msdn.microsoft.com/en-us/library/system.text.regularexpressions.regex.aspx
The 30 Minute Regex Tutorial
你好,
感谢您提供非常有用的文档链接.
Hello,
Thank you for links very useful documentations.
string remoteUri = "http://nbt.tj/ru/";
string pattern = "\bid\D\Dk_kurs\D\D1\sUSD\s\s\s\s\s\s\s\s\s4.\d\d\d\d\D\Dtd\D";
WebClient client = new WebClient();
Console.WriteLine("Downloading {0}", remoteUri);
string str = client.DownloadString(remoteUri);
Match match = Regex.Match(str, pattern);
MessageBox.Show(match.Groups[0].ToString());
运行此脚本时,系统显示错误无法识别的转义序列".
您能给我写出正确的解决方法吗?我要符合以下条件:
When I run this script the system show me the error "Unrecognized escape sequence".
Can you write me the correct way to fix it? I want to match the following:
id="k_kurs">1 USD 4.7554</td>
字符串模式= @"\ bid \ D \ Dk_kurs \ D \ D1 \ sUSD(.*)(\ d.\ d \ d \ d \ d)\ D \ Dtd \ D;
string pattern = @"\bid\D\Dk_kurs\D\D1\sUSD(.*)(\d.\d\d\d\d)\D\Dtd\D";
这篇关于将HTML代码与字符串模式匹配?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文