const regex = /(?<![src|href]\=\"(\n*|\s*)?)((?:https?):\/\/[\-A-Z0-9+\u0026\u2019@#\/%?=()~_|!:,.;]*[\-A-Z0-9+\u0026@#\/%=~()_|])/gi;
// Alternative syntax using RegExp constructor
// const regex = new RegExp('(?<![src|href]\\=\\"(\\n*|\\s*)?)((?:https?):\\\/\\\/[\\-A-Z0-9+\\u0026\\u2019@#\\\/%?=()~_|!:,.;]*[\\-A-Z0-9+\\u0026@#\\\/%=~()_|])', 'gi')
const str = `http://www.naver.com
http://www.google.com
http://www.google.com
http://www.naver.com
https://www.naver.com
www.naver.com
http://naver.com
www.naver.com
<img style="vertical-align: top;" alt="" src=" https://www.kita.net/mailclub/DailyTradeNews/images/gk_top_banner_191111.jpg" border="0">
<a target="_blank" href="https://www.kita.net/asocGuidance/notice/noticeDetail.do?pageIndex=1&nIndex=1792315&indexArray=&sortArray=&searchReqType=detail&searchStartDate=&searchEndDate=&searchCommCode1=&searchCondition=TITLE&searchKeyword=">
<a target="_blank" href=" https://www.kita.net/asocGuidance/notice/noticeDetail.do?pageIndex=1&nIndex=1792315&indexArray=&sortArray=&searchReqType=detail&searchStartDate=&searchEndDate=&searchCommCode1=&searchCondition=TITLE&searchKeyword=">
<a target="_blank" href="
https://www.kita.net/asocGuidance/notice/noticeDetail.do?pageIndex=1&nIndex=1792315&indexArray=&sortArray=&searchReqType=detail&searchStartDate=&searchEndDate=&searchCommCode1=&searchCondition=TITLE&searchKeyword=">
<a target="_blank" href= "
https://www.kita.net/asocGuidance/notice/noticeDetail.do?pageIndex=1&nIndex=1792315&indexArray=&sortArray=&searchReqType=detail&searchStartDate=&searchEndDate=&searchCommCode1=&searchCondition=TITLE&searchKeyword=">
(?<!\\=\\"(\\n|\\s).?)((?:https?):\\/\\/[\\-A-Z0-9+\\u0026\\u2019@#\\/%?=()~_|!:,.;]*[\\-A-Z0-9+\\u0026@#\\/%=~()_|])
(^|[\\s\\n]|<[A-Za-z]*\\/?>)((?:https?|ftp):\\/\\/[\\-A-Z0-9+\\u0026\\u2019@#\\/%?=()~_|!:,.;]*[\\-A-Z0-9+\\u0026@#\\/%=~()_|])
//최종
(?<![src|href]\\=\\"(\\n*|\\s*)?)((?:https?):\\/\\/[\\-A-Z0-9+\\u0026\\u2019@#\\/%?=()~_|!:,.;]*[\\-A-Z0-9+\\u0026@#\\/%=~()_|])`;
// Reset `lastIndex` if this regex is defined globally
// regex.lastIndex = 0;
let m;
while ((m = regex.exec(str)) !== null) {
// This is necessary to avoid infinite loops with zero-width matches
if (m.index === regex.lastIndex) {
regex.lastIndex++;
}
// The result can be accessed through the `m`-variable.
m.forEach((match, groupIndex) => {
console.log(`Found match, group ${groupIndex}: ${match}`);
});
}
Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for JavaScript, please visit: https://developer.mozilla.org/en/docs/Web/JavaScript/Guide/Regular_Expressions