我有這個字符串:的Javascript正則表達式返回不需要的字符
<AdParameters>
<VpaidClickThrough><![CDATA[http://media.adrcdn.com/ads/exit.html]]></VpaidClickThrough>
<VpaidClickTracking><![CDATA[]]></VpaidClickTracking>
<VpaidPath><![CDATA[http%3A%2F%2Fmedia.adrcdn.com%2Fads%2FAdrime%2F3130343734%2F61112%2F]]></VpaidPath>
<VpaidDuration><![CDATA[]]></VpaidDuration>
<VpaidId><![CDATA[e322f52bc813f05beacb6fe522a52f20]]></VpaidId>
</AdParameters>
<MediaFiles>
<MediaFile id="0" maintainAspectRatio="false" scalable="false" delivery="progressive" width="640" height="360" apiFramework='VPAID' type="application/x-shockwave-flash"> <![CDATA[http%3A%2F%2Fmedia.adrcdn.com%2Fads%2FAdrime%2F3130343734%2F61112%2Fmediafile_lineair_640x360.swf?VpaidId=e322f52bc813f05beacb6fe522a52f20&VpaidPath=http%3A%2F%2Fmedia.adrcdn.com%2Fads%2FAdrime%2F3130343734%2F61112%2F]]></MediaFile>
<MediaFiles>
而且我想從這裏所有的編碼的URL中提取。 所以我用這個正則表達式:
(http\%3A.*)\?|(http\%3A.*)\]\]
但我得到的是這樣的:「?」
http%3A%2F%2Fmedia.adrcdn.com%2Fads%2FAdrime%2F3130343734%2F61112%2F]]
http%3A%2F%2Fmedia.adrcdn.com%2Fads%2FAdrime%2F3130343734%2F61112%2Fmediafile_lineair_640x360.swf?
http%3A%2F%2Fmedia.adrcdn.com%2Fads%2FAdrime%2F3130343734%2F61112%2F]]
這是相當好,但我不希望最後的「]」和 如何獲取沒有這些結尾字符的網址?
這很奇怪,因爲在這裏嘗試我的正則表達式http://regex101.com/r/zS0tZ8它看起來很完美。
預先感謝您。
爲什麼你把\\] \\]在你的正則表達式呢? – Onheiron
您誤解了該頁面上的匹配項。數學小組下面的部分列出了正確的正則表達式部分,即括號中的部分。如果你看看實際的字符串,你會發現它們實際上是匹配額外的字符。 –