extract all anchor element from HTML string
2022年5月16日小于 1 分钟
extract all anchor element from HTML string
Question
Given a HTML string, write a function to extract the anchor <a/>
tag from it.
extract(`
<div>
<a>link1< / a><a href="https://bfe.dev">link1< / a>
<div<abbr>bfe</abbr>div>
<div>
<abbr>bfe</abbr><a href="https://bfe.dev" class="link2"> <abbr>bfe</abbr> <span class="l">l</span><span class="i">i</span> nk2 </a>
</div>
</div>
`)
// [
// '<a>link1< / a>',
// '<a href="https://bfe.dev">link1< / a>',
// '<a href="https://bfe.dev" class="link2"> <abbr>bfe</abbr> <span class="l">l</span><span //class="i">i</span> nk2 </a>'
//]
Code
/**
* @param {string} str
* @return {string[]}
*/
function extract(str) {
// your code here
}