通过javascript中的regex模式从字符串中获取子字符串

时间:2017-11-03 06:42:49

标签: javascript jquery regex

                                                           

        <div class="glint-main"> <!--match product container-->
            <div class="match-header sub-header"> <!--match product header-->
                This Item
            </div>
            <div class="match-product-details"> <!--match product information container-->
                <div class="product_page" role="link" tabindex="0" onkeypress="Glint.instance.statsPopup(event, &quot;product&quot;, &quot;01b8d44df669e090ba13bc32f1a90116&quot;, &quot;https://cdn.motherandbaby.co.uk/web/1/root/green-monkey-front-999-wwwmatchstickmonkeycom_w555_h555.jpg&quot;, &quot;1272961&quot;, &quot;https%3A%2F%2Frover.ffff.com%2Frover%2F1%2F710-53481-19255-0%2F1%3Fff3%3D4%26pub%3D5575316449%26toolid%3D11334%26campid%3D5338146124%26customid%3D%26mpre%3Dhttp%3A%2F%2Fwww.ebay.co.uk%2Fi%2F253013006125&quot;, &quot;d2c1a14a-c575-8a00-3e14-4ce959df2e08&quot;)" onclick="Glint.instance.statsPopup(event, &quot;product&quot;, &quot;01b8d44df669e090ba13bc32f1a90116&quot;, &quot;https://cdn.motherandbaby.co.uk/web/1/root/green-monkey-front-999-wwwmatchstickmonkeycom_w555_h555.jpg&quot;, &quot;1272961&quot;, &quot;https%3A%2F%2Frover.ffff.com%2Frover%2F1%2F710-53481-19255-0%2F1%3Fff3%3D4%26pub%3D5575316449%26toolid%3D11334%26campid%3D5338146124%26customid%3D%26mpre%3Dhttp%3A%2F%2Fwww.ebay.co.uk%2Fi%2F253013006125&quot;, &quot;d2c1a14a-c575-8a00-3e14-4ce959df2e08&quot;)">
                    <div class="match-product-img-container">
                        <img alt="" class="match-product-image" nopin="nopin" src="./Twelve Top Baby Teething Buys _ Mother&amp;Baby_files/1272961-thumb.jpg"> <!--match product image-->
                    </div>
                    <div class="match-product-description"> <!--match product text information container-->

                        <p class="match-name">

                                Matchstick Monkey Chewable Teething Gel...

                        </p>                            

                        <div class="product_price">
                            <span class="currency">£</span>
                            0.99
                        </div>




                    </div>
                </div>
            </div>
        </div> <!--end match product container-->


        <div class="similar-products">  <!--similar product for match container-->
            <div class="similar-header sub-header"> <!--similar product header-->
                Similar Item
            </div>

            <button class="all_item_btn" onclick="Glint.instance.statsPopup(event, &quot;link&quot;, &quot;01b8d44df669e090ba13bc32f1a90116&quot;, &quot;https://cdn.motherandbaby.co.uk/web/1/root/green-monkey-front-999-wwwmatchstickmonkeycom_w555_h555.jpg&quot;, &quot;1272961&quot;, &quot;Matchstick Monkey teething gel applicator&quot;, &quot;d2c1a14a-c575-8a00-3e14-4ce959df2e08&quot;)">
                Shop &gt;
            </button>

            <div class="toggle-container">
                <ul class="similar-product-list">


                <li class="similar-item-container">
                    <div class="product_page" role="link" tabindex="0" onkeypress="Glint.instance.statsPopup(event, &quot;similar&quot;, &quot;01b8d44df669e090ba13bc32f1a90116&quot;, &quot;https://cdn.motherandbaby.co.uk/web/1/root/green-monkey-front-999-wwwmatchstickmonkeycom_w555_h555.jpg&quot;, &quot;1272965&quot;, &quot;https%3A%2F%2Frover.ffff.com%2Frover%2F1%2F710-53481-19255-0%2F1%3Fff3%3D4%26pub%3D5575316449%26toolid%3D11334%26campid%3D5338146124%26customid%3D%26mpre%3Dhttp%3A%2F%2Fwww.ebay.co.uk%2Fi%2F302247889639&quot;, &quot;d2c1a14a-c575-8a00-3e14-4ce959df2e08&quot;)" onclick="Glint.instance.statsPopup(event, &quot;similar&quot;, &quot;01b8d44df669e090ba13bc32f1a90116&quot;, &quot;https://cdn.motherandbaby.co.uk/web/1/root/green-monkey-front-999-wwwmatchstickmonkeycom_w555_h555.jpg&quot;, &quot;1272965&quot;, &quot;https%3A%2F%2Frover.ffff.com%2Frover%2F1%2F710-53481-19255-0%2F1%3Fff3%3D4%26pub%3D5575316449%26toolid%3D11334%26campid%3D5338146124%26customid%3D%26mpre%3Dhttp%3A%2F%2Fwww.ebay.co.uk%2Fi%2F302247889639&quot;, &quot;d2c1a14a-c575-8a00-3e14-4ce959df2e08&quot;)">
                        <span class="clipped"> - opens in new window or tab</span>
                        <div class="similar_image_container">
                            <img alt="" class="similar-product-image" src="./Twelve Top Baby Teething Buys _ Mother&amp;Baby_files/1272965-thumb.jpg"><!--similar product image-->
                        </div>
                        <div class="similar-product-description"> <!--similar product text information container-->
                            <p class="name">Matchstick Monkey Teething Gel</p>

                            <div class="product_price">
                                <span class="currency">£</span>
                                19.23
                            </div>

                        </div>
                    </div>
                </li>


                </ul>
            </div>
        </div><!--end similar product for match container-->

    </div><!--end product full border-->
</div><!--end product full container-->


    <div class="ebay_footer">
        <span class="clipped"> - opens in new window or tab</span>
        <img alt="ebay logo" src="./Twelve Top Baby Teething Buys _ Mother&amp;Baby_files/ebay-transparent-logo.png">
    </div>

                                                           

        <div class="similar-products">  <!--similar product for match container-->
            <div class="similar-header sub-header"> <!--similar product header-->
                Similar Item
            </div>

            <button class="all_item_btn" onclick="Glint.instance.statsPopup(event, &quot;link&quot;, &quot;46843f60877ce41020b2c34e2832788f&quot;, &quot;https://cdn.motherandbaby.co.uk/web/1/root/uki-be_w555_h555.jpg&quot;, &quot;1272958&quot;, &quot;Baby Kids Silicone Elephant Teething Pacifier &quot;, &quot;d2c1a14a-c575-8a00-3e14-4ce959df2e08&quot;)">
                Shop &gt;
            </button>

            <div class="toggle-container">
                <ul class="similar-product-list">


                <li class="similar-item-container">
                    <div class="product_page" role="link" tabindex="0" onkeypress="Glint.instance.statsPopup(event, &quot;similar&quot;, &quot;46843f60877ce41020b2c34e2832788f&quot;, &quot;https://cdn.motherandbaby.co.uk/web/1/root/uki-be_w555_h555.jpg&quot;, &quot;1272958&quot;, &quot;https%3A%2F%2Frover.ffff.com%2Frover%2F1%2F710-53481-19255-0%2F1%3Fff3%3D4%26pub%3D5575316449%26toolid%3D11334%26campid%3D5338146124%26customid%3D%26mpre%3Dhttp%3A%2F%2Fwww.ebay.co.uk%2Fi%2F291879917428&quot;, &quot;d2c1a14a-c575-8a00-3e14-4ce959df2e08&quot;)" onclick="Glint.instance.statsPopup(event, &quot;similar&quot;, &quot;46843f60877ce41020b2c34e2832788f&quot;, &quot;https://cdn.motherandbaby.co.uk/web/1/root/uki-be_w555_h555.jpg&quot;, &quot;1272958&quot;, &quot;https%3A%2F%2Frover.ffff.com%2Frover%2F1%2F710-53481-19255-0%2F1%3Fff3%3D4%26pub%3D5575316449%26toolid%3D11334%26campid%3D5338146124%26customid%3D%26mpre%3Dhttp%3A%2F%2Fwww.ebay.co.uk%2Fi%2F291879917428&quot;, &quot;d2c1a14a-c575-8a00-3e14-4ce959df2e08&quot;)">
                        <span class="clipped"> - opens in new window or tab</span>
                        <div class="similar_image_container">
                            <img alt="" class="similar-product-image" src="./Twelve Top Baby Teething Buys _ Mother&amp;Baby_files/1272958-thumb.jpg"><!--similar product image-->
                        </div>
                        <div class="similar-product-description"> <!--similar product text information container-->
                            <p class="name">New 1xBaby Kids Silicone</p>

                            <div class="product_price">
                                <span class="currency">£</span>
                                2.04
                            </div>

                        </div>
                    </div>
                </li>


                </ul>
            </div>
        </div><!--end similar product for match container-->

    </div><!--end product full border-->
</div><!--end product full container-->


    <div class="ebay_footer">
        <span class="clipped"> - opens in new window or tab</span>
        <img alt="ebay logo" src="./Twelve Top Baby Teething Buys _ Mother&amp;Baby_files/ebay-transparent-logo.png">
    </div>

function Extractallroverlinks(document_root) {
    debugger;
    try {
        var number = 0;
        var listoflinks = [];
        var linkname = '';
        var links = ["rover.ffff.com"];
        var html = '';
        var subStr = document_root.documentElement.outerHTML.match("(http|ftp|https)://([\w_-]+(?:(?:\.[\w_-]+)+))([\w.,@?^=%&:/~+#-]*[\w@?^=%&/~+#-])?");

    }
    catch (ex) {
        alert(ex);
    }
    return listoflinks;
}

我需要包含 rover.ffff.com 的子字符串,从https或http到链接的末尾。 喜欢这个虚拟的HTML我需要这样的结果

listoflinks[0]=https%3A%2F%2Frover.ffff.com%2Frover%2F1%2F710-53481-19255-0%2F1%3Fff3%3D4%26pub%3D5575316449%26toolid%3D11334%26campid%3D5338146124%26customid%3D%26mpre%3Dhttp%3A%2F%2Fwww.ebay.co.uk%2Fi%2F302247889639&quot;, &quot;d2c1a14a-c575-8a00-3e14-4ce959df2e08&quot;)

listoflinks[1]=https%3A%2F%2Frover.ffff.com%2Frover%2F1%2F710-53481-19255-0%2F1%3Fff3%3D4%26pub%3D5575316449%26toolid%3D11334%26campid%3D5338146124%26customid%3D%26mpre%3Dhttp%3A%2F%2Fwww.ebay.co.uk%2Fi%2F291879917428&quot;, &quot;d2c1a14a-c575-8a00-3e14-4ce959df2e08&quot;)

listoflinks[2]=https%3A%2F%2Frover.ffff.com%2Frover%2F1%2F710-53481-19255-0%2F1%3Fff3%3D4%26pub%3D5575316449%26toolid%3D11334%26campid%3D5338146124%26customid%3D%26mpre%3Dhttp%3A%2F%2Fwww.ebay.co.uk%2Fi%2F291879917428&quot;, &quot;d2c1a14a-c575-8a00-3e14-4ce959df2e08&quot;)

listoflinks[3]=https%3A%2F%2Frover.ffff.com%2Frover%2F1%2F710-53481-19255-0%2F1%3Fff3%3D4%26pub%3D5575316449%26toolid%3D11334%26campid%3D5338146124%26customid%3D%26mpre%3Dhttp%3A%2F%2Fwww.ebay.co.uk%2Fi%2F291879917428&quot;, &quot;d2c1a14a-c575-8a00-3e14-4ce959df2e08&quot;)

0 个答案:

没有答案