2017-06-19 86 views
-1

我有一個Google腳本從URL獲取內容。我使用正則表達式來找到我需要抓住的內容,例如:谷歌腳本的正則表達式 - 已獲取HTML

var htmlSubCategory = UrlFetchApp.fetch(url).getContentText();  
var regexpFindingAllLinks = /<div class="small-12 medium-5 large-4 columns"><a href="\/(.*?)\//g 
var linksProducts = regexpFindingAllLinks.exec(htmlSubCategory); 

我有一個書面方式其他正則表達式查找的一些項目的標題問題。源代碼如下所示:

<p class="heading"><span class="highlight-ico"></span><a href="/url-1/" title="some title for URL 1">Title I need to grab</a></p> 
<p class="heading"><span class="highlight-ico"></span><a href="/url-2/" title="some title for URL 2">Title I need to grab</a></p> 

基本上,我需要有一個正則表達式,將尋找

<p class="heading"><span class="highlight-ico"></span><a href="(can be any content)" title="(can be any content)">(grab this content)</a></p> 

其次,我想有一個正則表達式能吸引僅供參考數字,這一下像這樣:X12345678,其中X是一個字母,後面跟着8位數字。

我是新來的這些腳本,任何幫助將不勝感激。

+0

哦,我的壞,評論刪除:p –

+1

問題帖子應該只有一個問題。 –

回答

0

shouldn't use regex to parse HTML,但如果你不能做任何其他方式使用:

/<p class="heading"><span class="highlight-ico"><\/span><a href="[^"]*" title="[^"]*">((?:(?!<\/a>).)*)<\/a><\/p>/ 

有關(選配參考號碼)你的第二個問題,用這個:

/X\d{8}/