javascriptregexgoogle-apps-scripthtml-parsing

Javascript regex to extract title and iframe


A Google apps script gets HTTP response content text. The excerpt as is below.

<p style="text-align: left;"><span style="background-color: rgb(242, 195, 20);"><span style="color: rgb(192, 80, 77);">Disclaimer:</span></span><span style="background-color: rgb(255, 255, 255);">Please note,</span><a href="http://www.g00gl3.com"><span style="background-color: rgb(255, 255, 255);">http://www.g00gl3.com</span></a><span style="background-color: rgb(255, 255, 255);"> or </span><a href="http://www.g00gl3.com"><span style="background-color: rgb(255, 255, 255);">www.G00gl3.com</span></a><span style="background-color: rgb(255, 255, 255);"> is only video embedding websites. All of the videos found here come from 3rd party video hosting sites. We do not host any of the videos. Please contact to appropriate video hosting site for any video removal.</span></p>
<div style="text-align: center;"><strong><span style="background-color: rgb(255, 255, 255);">Dailymotion  <br><br></span></strong></div>
<div style="text-align: center;"><iframe src="http://www.dailymotion.com/embed/video/foo1234567890bar? syndication=202279" width="640" height="360" frameborder="0"></iframe></div>
<div style="text-align: center;"><strong><span style="background-color: rgb(255, 255, 255);">Alternate Video  <br><br></span></strong></div>
<div style="text-align: center;"><iframe src="http://hqq.tv/player/embed_player.php?vid=1234567890&amp;autoplay=no" width="720" height="450" frameborder="0"></iframe></div>

From this excerpt there is a need to extract title (Dailymotion or Alternate Video) and iframe.

Matching only iframe is already done.

/<iframe(.*)\/iframe>/g

Now the expected is

Dailymotion  <br><br></span></strong></div>
<div style="text-align: center;"><iframe src="http://www.dailymotion.com/embed/video/foo1234567890bar? syndication=202279" width="640" height="360" frameborder="0"></iframe>

and

Alternate Video  <br><br></span></strong></div>
<div style="text-align: center;"><iframe src="http://hqq.tv/player/embed_player.php?vid=1234567890&amp;autoplay=no" width="720" height="450" frameborder="0"></iframe>

Can anybody help to write regex to fetch only above.


Solution

  • Try this, should work:

    /255\);">([a-zA-Z]+\s+.*)<br><br>/g