从大html中获取一个小字符串(REGEXP)

时间:2014-04-16 15:50:57

标签: javascript php regex expression

我正在搜索一个他真的很喜欢regexp的人。

看看这个HTML代码:

<div class="market_listing_table_header">
        <div class="market_listing_right_cell market_listing_their_price market_sortable_column">PRICE<span class="market_sort_arrow" style="display:none;"> ?</span></div>
        <div class="market_listing_right_cell market_listing_num_listings market_sortable_column">QUANTITY<span class="market_sort_arrow" style="display:none;"> ?</span></div>
                <div class="market_sortable_column"><span class="market_listing_header_namespacer"></span>NAME<span class="market_sort_arrow" style="display:none;"> ?</span></div>
    </div>

<a class="market_listing_row_link" href="http://steamcommunity.com/market/listings/730/Sticker%20Capsule">
    <div class="market_listing_row market_recent_listing_row market_listing_searchresult" id="result_0">
                <img id="result_0_image" src="http://cdn.steamcommunity.com/economy/image/oPg27gVBfBTgdCk41FdRyxi0_F9BMXJUNLr6IjCxGWxp8wEVXF06BkCtNcbyNw1FALOnGEguclAysf0wMacOZmaxBh9KSCcNe-A32vprQ1YCofxKJG0pUDK19jFBsgxqY65AVBsNeAcUtDXMqyxeURPzuhkdLW5bM7yic3-mCD9s-EhOGgl7VUa3YZCxaAJS/62fx62f" style="border-color: #D2D2D2;" class="market_listing_item_img" alt="">      
                <div class="market_listing_right_cell market_listing_their_price">
            <span class="market_table_value">
                Starting at:<br>
                <span style="color:white">$10.03 USD</span>
            </span>
        </div>
        <div class="market_listing_right_cell market_listing_num_listings">
            <span class="market_table_value">
                <span class="market_listing_num_listings_qty">568,694</span>
            </span>
        </div>

                <div class="market_listing_item_name_block">
            <span id="result_0_name" class="market_listing_item_name" style="color: #D2D2D2;">Sticker Capsule</span>
            <br>
            <span class="market_listing_game_name">Counter-Strike: Global Offensive</span>
        </div>
    </div>
</a>

<a class="market_listing_row_link" href="http://steamcommunity.com/market/listings/730/CS%3AGO%20Weapon%20Case%203">
    <div class="market_listing_row market_recent_listing_row market_listing_searchresult" id="result_1">
                <img id="result_1_image" src="http://cdn.steamcommunity.com/economy/image/S7adkJSkWAGxsBVYqLRazfP6VyHQ1FZBZX7GQkxSEmqCvaprzbgeExFpCaaO1AZD6_0MZtnLVkVjdcFQTUQFYI3_rWHbrQMYKiQLuoaISFDp71c0tY0YQHZ_8BBMQ1I2h7PoNtvtWk9MdlP91Z5fB6LtFDPZzU1ON36aG1UXUzzXtbwyi_McGBI=/62fx62f" style="border-color: #D2D2D2;" class="market_listing_item_img" alt="">      
                <div class="market_listing_right_cell market_listing_their_price">
            <span class="market_table_value">
                Starting at:<br>
                <span style="color:white">$0.04 USD</span>
            </span>
        </div>
        <div class="market_listing_right_cell market_listing_num_listings">
            <span class="market_table_value">
                <span class="market_listing_num_listings_qty">233,789</span>
            </span>
        </div>

                <div class="market_listing_item_name_block">
            <span id="result_1_name" class="market_listing_item_name" style="color: #D2D2D2;">CS:GO Weapon Case 3</span>
            <br>
            <span class="market_listing_game_name">Counter-Strike: Global Offensive</span>
        </div>
    </div>
</a>

我需要这部分:(粗体)

$ 0.03 美元

我每次都需要它时都需要它

从以下开始:&lt; span style =&#34; color:white&#34;&gt; AND&lt; /跨度&GT;

有人知道给我一个提示吗?

亲切的问候, 弗雷迪

1 个答案:

答案 0 :(得分:0)

您可以使用此正则表达式:

/<span style="color:white">.*?([0-9]+(?:\.[0-9]*)?).*?<\/span>/

第一组将包含您想要的内容。