在Javascript中使用正则表达式来获取RSS / XML标记之间的文本

时间:2013-03-04 17:22:38

标签: xml regex json rss

我正在创建一个jQuery Mobile应用程序,它可以解析RSS提要并动态地将条目输入到DOM中。我正在使用.contentSnippet功能从<description>...</description>中抓取第一句或第二句,我想在<em>...</em>之间获得内容。如何使用Javascript和RegEx选择此内容?以下是我正在使用的RSS的样子。

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

我将Feed作为JSON对象引入。

1 个答案:

答案 0 :(得分:0)

如果您确定要使用正则表达式,可以使用

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