const regex = /<tr>\n\s*<td width="70"><strong>Released:<\/strong><\/td>\n\s*<td>(.*)<\/td>\n\s*<\/tr>\n\s*<tr>\n\s*<td width="70"><strong>Runtime:<\/strong><\/td>\n\s*<td>(.*)<\/td>\n\s*<\/tr>\n\s*<tr>\n\s*<td width="70"><strong>Genres:<\/strong><\/td>\n\s*<td><span class="movie_info_genres"><a\s[^<>]*>([^<>]*)<\/a>/gm;
// Alternative syntax using RegExp constructor
// const regex = new RegExp('<tr>\\n\\s*<td width="70"><strong>Released:<\\\/strong><\\\/td>\\n\\s*<td>(.*)<\\\/td>\\n\\s*<\\\/tr>\\n\\s*<tr>\\n\\s*<td width="70"><strong>Runtime:<\\\/strong><\\\/td>\\n\\s*<td>(.*)<\\\/td>\\n\\s*<\\\/tr>\\n\\s*<tr>\\n\\s*<td width="70"><strong>Genres:<\\\/strong><\\\/td>\\n\\s*<td><span class="movie_info_genres"><a\\s[^<>]*>([^<>]*)<\\\/a>', 'gm')
const str = `<tr>
<td width="70"><strong>Released:</strong></td>
<td>July 25, 2014</td>
</tr>
<tr>
<td width="70"><strong>Runtime:</strong></td>
<td>90 mins </td>
</tr>
<tr>
<td width="70"><strong>Genres:</strong></td>
<td><span class="movie_info_genres"><a href="/?genre=Action">Action</a> <a href="/?genre=Sci-Fi">Sci-Fi</a> </span></td>
</tr>
<tr>
<td width="70"><strong>Actors:</strong></td>
<td><span class="movie_info_actors">
<a href="/?actor_name= Analeigh Tipton "> Analeigh Tipton </a> <a href="/?actor_name= Morgan Freeman "> Morgan Freeman </a> <a href="/?actor_name= Scarlett Johansson "> Scarlett Johansson </a> <a href="/?actor_name=Min-sik Choi">Min-sik Choi</a> </span></td>
</tr>`;
// Reset `lastIndex` if this regex is defined globally
// regex.lastIndex = 0;
let m;
while ((m = regex.exec(str)) !== null) {
// This is necessary to avoid infinite loops with zero-width matches
if (m.index === regex.lastIndex) {
regex.lastIndex++;
}
// The result can be accessed through the `m`-variable.
m.forEach((match, groupIndex) => {
console.log(`Found match, group ${groupIndex}: ${match}`);
});
}
Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for JavaScript, please visit: https://developer.mozilla.org/en/docs/Web/JavaScript/Guide/Regular_Expressions