© Zsolt Nagy 2018
Zsolt NagyRegex Quick Syntax Referencehttps://doi.org/10.1007/978-1-4842-3876-9_11

11. Parsing HTML Code and URL Query Strings with Regular Expressions

Zsolt Nagy1 
(1)
Berlin, Germany
 

In this chapter, we will use JavaScript to parse an HTML document and process the query string of a URL.

Parsing HTML Tags

Exercise 1: Suppose an HTML document is given. Extract all the <td> tags using a regular expression, and print their content to the console. You can assume any content including newline characters inside the <td> tags. The <td> tags may have attributes.

Example Input:

const table = `
    <table>
        <tr>
            <td class="first">text 1</td>
            <TD>text 2</TD>
        </tr>
        <tr>
            <td>text trés</td>

Get Regex Quick Syntax Reference: Understanding and Using Regular Expressions now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.