Regular Expression using Regex c#

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • souphaphone
    New Member
    • Feb 2008
    • 1

    Regular Expression using Regex c#

    can anyone help me to get data from this

    <td class="detail12 " align="center" bgcolor="#b6e2f f">9,034</td>

    i wanna get 9,034 but m stuck at using the code...
    m trying to use this.. but they have zero matches:(

    Regex regex = new Regex(@"<td\s+c lass=\"detail12 \"\s+.*?>(.* ?)</td>");

    there's also a syntax error occur up there

    please help me..

    thanks in advance

    Nick
  • kreismaler
    New Member
    • Feb 2008
    • 3

    #2
    In fact your Regex is correct. The problem is that verbatim strings (@"...") don't support the backslash ("\") as escape character. To escape a double quote in a verbatim string use two double quotes instead.

    Maybe some code is more helpful:
    Code:
                string test = @"<td class=""detail12"" align=""center"" bgcolor=""#b6e2ff"">9,034</td>";
                Console.WriteLine(test);
                Regex regex = new Regex(@"<td\s+class=""detail12""\s+.*?>(.*?)</td>");
                Console.WriteLine(regex.IsMatch(test));      // returns "True"
    I must admit that I didn't test for the resulting matches, but I understood from your post that you have troubles with the syntax. So give it try ...

    Regards,
    K

    Comment

    Working...