首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > asp.net >

C# 正则

2013-04-05 
C# 正则求助div classt_Tooltip t_Tooltip_cloud t_hidden styleleft: -10000px top: -10000pxz-i

C# 正则求助


<div class="t_Tooltip t_Tooltip_cloud t_hidden" style="left: -10000px; top: -10000px;
    z-index: 999999; transition-duration: 220ms; display: block; width: 140px; height: 110px;">
    <div class="t_Shadow" style="top: 0px; left: 0px; width: 140px; height: 110px;">
        <div class="t_ShadowBubble" style="width: 140px; height: 110px;">
            <canvas width="280" height="220" style="width: 140px; height: 110px;"></canvas>
        </div>
    </div>
    <div class="t_Skin" style="width: 136px; height: 105px; top: 3px; left: 2px;">
        <div class="t_Bubble" style="width: 136px; height: 105px; top: 0px; left: 0px;">
            <canvas width="272" height="210" style="width: 136px; height: 105px;"></canvas>
        </div>
    </div>
    <div class="t_Content" style="left: 3px; top: 11px; width: 100%;">
        <div class="t_ContentContainer t_clearfix t_Content_cloud" style="width: auto; height: auto;">
            <div style="" class="htmlTooltip">
                <h1>
                    金屬</h1>
                <div class="splitLine">
                </div>
                <table class="resourceTooltip">
                    <tbody>
                        <tr>
                            <th>
                                現有量:
                            </th>
                            <td>
                                <span class="">3,293,129</span>
                            </td>


                        </tr>
                        <tr>
                            <th>
                                儲存容量:
                            </th>
                            <td>
                                <span class="">33,005,000</span>
                            </td>
                        </tr>
                        <tr>
                            <th>
                                當前產量:
                            </th>
                            <td>
                                <span class="undermark">+19,844</span>
                            </td>
                        </tr>
                        <tr>
                            <th>
                                保護倉容量:
                            </th>
                            <td>


                                <span class="overermark">0</span>
                            </td>
                        </tr>
                    </tbody>
                </table>
            </div>
        </div>
    </div>
</div>


<div class="t_Tooltip t_Tooltip_cloud t_hidden" style="left: -10000px; top: -10000px;
    z-index: 999999; transition-duration: 220ms; display: block; width: 133px; height: 110px;">
    <div class="t_Shadow" style="top: 0px; left: 0px; width: 133px; height: 110px;">
        <div class="t_ShadowBubble" style="width: 133px; height: 110px;">
            <canvas width="266" height="220" style="width: 133px; height: 110px;"></canvas>
        </div>
    </div>
    <div class="t_Skin" style="width: 129px; height: 105px; top: 3px; left: 2px;">
        <div class="t_Bubble" style="width: 129px; height: 105px; top: 0px; left: 0px;">
            <canvas width="258" height="210" style="width: 129px; height: 105px;"></canvas>
        </div>
    </div>
    <div class="t_Content" style="left: 3px; top: 11px; width: 100%;">
        <div class="t_ContentContainer t_clearfix t_Content_cloud" style="width: auto; height: auto;">
            <div style="" class="htmlTooltip">
                <h1>
                    晶體</h1>
                <div class="splitLine">
                </div>
                <table class="resourceTooltip">
                    <tbody>
                        <tr>
                            <th>


                                現有量:
                            </th>
                            <td>
                                <span class="">1,396,821</span>
                            </td>
                        </tr>
                        <tr>
                            <th>
                                儲存容量:
                            </th>
                            <td>
                                <span class="">5,355,000</span>
                            </td>
                        </tr>
                        <tr>
                            <th>
                                當前產量:
                            </th>
                            <td>
                                <span class="undermark">+8,677</span>
                            </td>
                        </tr>


                        <tr>
                            <th>
                                保護倉容量:
                            </th>
                            <td>
                                <span class="overermark">0</span>
                            </td>
                        </tr>
                    </tbody>
                </table>
            </div>
        </div>
    </div>
</div>



上面是两段结构一样的代码。
我希望【分别】获取到
第一段里面的:19,844

第二段里面的:8,677


 private static String GetValueByRegex(String regex, String html)
        {
            var reg = new Regex(regex, RegexOptions.Singleline | RegexOptions.IgnoreCase);

            var value = reg.Match(html).Groups[1].Value;

            return value.Trim();
        }


如果可以话通过这个方法里面的代码来获取。
[解决办法]
(?is)<tr>\s*<th>\s*當前產量:\s*</th>\s*<td>\s*<span[^>]*?class="undermark">\+(?<span>.*?)</span>\s*</td>\s*</tr>

简单点就这样 (?is)<span[^>]*?class="undermark">\+(?<span>.*?)</span>
[解决办法]
取Groups["span"].Value

这个方法private static String GetValueByRegex(String regex, String html)

regex参数传上面的正则就行了
[解决办法]
引用:
版主,从去年的9月份开始我就一直想学正则,
有正则相关的入门级书籍或资料推荐吗?


这是版主总结的帖子,非常有参考价值->
http://bbs.csdn.net/topics/380196757

热点排行