Регулярки C#

Discussion in 'С/С++, C#, Rust, Swift, Go, Java, Perl, Ruby' started by cheater_man, 29 Oct 2011.

  1. cheater_man

    cheater_man Member

    Joined:
    13 Nov 2009
    Messages:
    651
    Likes Received:
    44
    Reputations:
    7
    Кто сталкивался с регулярками?
    В c# есть специальный класс regex
    Как спарсить
    Code:
    MasterCard
    из этого
    Code:
    <tr valign="top"><td><b>Type:</b></td><td><h2 style="font-size: 1em; display: inline; font-weight: normal">MasterCard</h2></td>
     
  2. doublex

    doublex New Member

    Joined:
    22 Jan 2011
    Messages:
    3
    Likes Received:
    0
    Reputations:
    0
    Я сталкивался.

    Code:
    using System.Text.RegularExpressions;
    ...
    string source = "<tr valign=\"top\"><td><b>Type:</b></td><td><h2 style=\"font-size: 1em; display: inline; font-weight: normal\">MasterCard</h2></td>";
    string pattern = "normal\">(.*)</h2>";
    Match match = Regex.Match(source,pattern);
    Console.WriteLine(match.Groups[1]);
    Console.ReadLine();
     
  3. cheater_man

    cheater_man Member

    Joined:
    13 Nov 2009
    Messages:
    651
    Likes Received:
    44
    Reputations:
    7
    Спасибо ограмное=) то что надо=)