J'ai un flux de source de site Web que j'essaye d'analyser. Mon Regex actuel est le suivant:Aide simple regex en utilisant C# (motif Regex inclus)
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);
Mais cela ne correspond plus aux liens. J'ai inclus un exemple de chaîne here.
Fondamentalement, je suis en train de les faire correspondre:
<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**
Dans l'exemple que j'ai posté, il y a au moins 3, je ne comptais pas les autres.
Aussi j'utilise RegexHero (en ligne et gratuit) pour voir mon correspondant interactivement avant de l'ajouter au code.
Utilisez HtmlAgilityPack. – SLaks
@Joan Venge Pour la référence: http://stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags –
Merci pst, je n'en ai pas vu un. –