https로 시작하는 url을 가져오기 위해 정규표현식을 작성
/\bhttps\S*/gm
space가 아닌 문자가* : 있거나 없거나 많거나문자열.match(정규표현식)로 일치하는 문자열의 배열을 반환
let urlArr = article.match(/\bhttps\S*/gm);
배열 urlArr에는 https로 시작하는 문자열들이 담김
배열요소들을 순회하면서 replace 함수로 <a태그>를 포함한 문자열로 치환해준다
문자열. replace( pattern , 치환할 문자열)
urlArr.forEach( url => {
newArticle = newArticle.replace(url,`<a href="${url}">클릭</a>`);
})
function solution(article) {
let urlArr = article.match(/\bhttps\S*/gm);
let newArticle = article;
urlArr.forEach( url => {
newArticle = newArticle.replace(url,`<a href="${url}">클릭</a>`);
})
return newArticle;
}