Regular Expressions


#1

I am trying to parse the respond of an http request that will return the HTML source code of a URL that the user will provide. I got to the part where I fully receive the HTML code and I store that in a Promise. Now I am trying to use Regex to parse the Html and return the piece I want. However the regex search I am applying only returns the first match in a RegexMatchArray

I guess I am using a typescript approach(it would be great if someone can confirm that). If there is an easier approach with Angular or NativeScript Module I would like to have it

Here is my code:
export class HomeComponent {
regex:string;
url:string;
html: Promise <>string; // I have the string inside <> but the forum won’t show that
metaTag: RegExp;
match: RegExpExecArray;
match2: RegExpMatchArray;

getHtmlFromURL(){

    var httpClient= require("http");     
    this.metaTag = new RegExp("<meta name=\"(.+?)\" content=\"(.+?)\"");
    try{   

        httpClient.getString("https://www.oldnational.com")
            .then(html=> {

                console.log("OnFulfilled !");
                this.html=html;
        
                this.match2 = this.html.toString().match(this.metaTag);
                this.match = this.metaTag.exec(html);
                //The previous two lines return the exact same data
                // which is the first match of the regex search broken into 3 parts
                // 0:  "<meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\""  
                // 1: "viewport"
                // 2: "width=device-width, initial-scale=1.0"
                // keeping in mind that the html string has more 4 matches for the given regex ("<meta name=\"(.+?)\" content=\"(.+?)\"")
           },
             ()=>{
                console.log("OnRejected !");
             }
        );
    }
    catch(error)
    {
        console.log("Caught an error: "+ error);
    }

} 

}