簡體   English   中英

在Javascript中使用正則表達式在RSS / XML標簽之間獲取文本

[英]Using Regular Expression in Javascript to grab text between RSS/XML tag

我正在創建一個jQuery Mobile應用程序,該應用程序解析RSS feed並動態將條目輸入DOM。 我正在使用.contentSnippet功能從<description>...</description>抓取第一句話或第二句話,而我只是想讓內容在<em>...</em> 如何使用Javascript和RegEx選擇此內容? 這是我正在使用的RSS外觀。

<description><![CDATA[<font size="2"><em>American Banker Magazine (03/13) Fest, Glen</em>...</description>

我將提要作為JSON對象引入。

如果確定要使用正則表達式,則可以使用

var str = '<description><![CDATA[<font size="2"><em>American Banker Magazine (03/13) Fest, Glen</em>...</description>',
    m = str.match( /<em>(.+?)<\/em>/ );

console.log( m && m[1] || 'Nothing doing' );
// American Banker Magazine (03/13) Fest, Glen

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM