【发布时间】:2011-09-25 03:55:11
【问题描述】:
我有一些我正在尝试解析的网站源流。我目前的正则表达式是这样的:
Regex pattern = new Regex (
@"<a\b # Begin start tag
[^>]+? # Lazily consume up to id attribute
id\s*=\s*['""]?thread_title_([^>\s'""]+)['""]? # $1: id
[^>]+? # Lazily consume up to href attribute
href\s*=\s*['""]?([^>\s'""]+)['""]? # $2: href
[^>]* # Consume up to end of open tag
> # End start tag
(.*?) # $3: name
</a\s*> # Closing tag",
RegexOptions.Singleline | RegexOptions.IgnoreCase | RegexOptions.IgnorePatternWhitespace );
但它不再匹配链接。我包含了一个示例字符串here。
基本上我正在尝试匹配这些:
<a href="http://visitingspain.com/forum/f89/how-to-get-a-travel-visa-3046631/" id="thread_title_3046631">How to Get a Travel Visa</a>
"http://visitingspain.com/forum/f89/how-to-get-a-travel-visa-3046631/" is the **Link**
304663` is the **TopicId**
"How to Get a Travel Visa" is the **Title**
在我发布的示例中,至少有 3 个,其他的我没有计算。
我还使用RegexHero(在线免费)在将匹配项添加到代码之前以交互方式查看匹配项。
【问题讨论】:
-
@Joan Venge 供参考:stackoverflow.com/questions/1732348/…
-
谢谢 pst,没看过那个。