0

I'm creating a jQuery Mobile app that parses an RSS feed and dynamically inputs the entries into the DOM. I'm using the .contentSnippet feature to grab the first sentence or two from the <description>...</description> and I'd like to just have the content between <em>...</em>. How do I select this content using Javascript and RegEx? Here is what the RSS looks like that I'm working with.

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

I'm bringing the feed in as a JSON object.

  • 4
    Read this http://stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags . Don't use Regular Expressions, instead use an XML Parser, – Benjamin Gruenbaum Mar 04 '13 at 17:24
  • similar question : `http://stackoverflow.com/questions/5227592/extract-cdata-from-rss-xml-using-javascript` – Maulik Vora Mar 04 '13 at 17:24

1 Answers1

0

If you are sure you want to use a regular expression, you could use

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
MikeM
  • 13,156
  • 2
  • 34
  • 47