I have a string that contains names (firstname and lastname), username and email addresses of persons. I need to get the names and email addresses and add them into an HTML table using regex (regular expressions).
The HTML table should look like this:
This is my javascript code so far:
// this is some example of the names & email adresses - they are fake
const outlook = "Anders Jensen (EAAAANJE) <eaaaanje@students.eaax.dk>; Bodil Pedersen (EAAABOPE) <eaaabope@students.eaax.dk>; Åse Andersen (EAAAIDAN) <eaaaasan@students.eaax.dk>; Mühl Svendsen (EAAAPESV) <eaaamusv@students.eaax.dk>";
// we find all the emails & names of the students
let regexEmail = /\<.*?\>/g;
let regexName = /\w+\s\w+\s/gi;
// an array of all the td-tags
let tdTags = document.querySelectorAll("td");
// The emails and names are inserted in the table
for(let i = 0; regexName.exec(outlook) !== null; i++) {
tdTags[i].innerHTML = regexName.exec(outlook)[i]; // name
tdTags[i].nextSibling.innerHTML = regexEmail.exec(outlook)[i]; // e-mail
}
The problem is it only prints the one name and insert it in the first td. And the e-mail adresses can't be retrieved. I'm still a beginner in Regex so I can't see what I'm doing wrong.
Any help would be appreciated!