Avatar of the person chatting

.replace(/\[(.*?)\]\(.*?\)/gi, "") how can i remain content of (.*?) and (.*?)?

To capture the content of the first set of parentheses, you can use the first capturing group (i.e. (.*?)). Similarly, to capture the content of the second set of parentheses, you can use the second capturing group (i.e. (.*?)).

You can reference the captured groups using $1, $2, $3, etc.

For example, let's say you want to replace the matched text with just the content of the first set of parentheses, you can use the following replacement string:

$1

And you want to replace the matched text with both contents of the two set of parentheses, you can use the following replacement string:

$1 $2
Avatar of the person chatting

in this regex change '(' and ')' to " "

To replace the ( and ) characters with a space character in the matched text, you can use the following replacement string:

.replace(/\[(.*?)\]\(.*?\)/gi, "$1 $2").replace(/[()]/g, " ")

This will first capture the contents of the first and second set of parentheses (i.e. $1 and $2) and then replace all ( and ) characters with a space character.

Alternatively, You can use this one as well

.replace(/\[(.*?)\]\((.*?)\)/gi, "$1 $2")

and it will also give you the same result.

Avatar of the person chatting

if (typeof window !== "undefined") { window.addEventListener("load", () => { loadToc(); }); }

This code is checking if the current environment is a browser (by checking if the window object is defined) and if it is, it is adding an event listener to the load event of the window. When the load event is fired, the loadToc() function will be called.

The load event is fired when the page and all its resources (such as images, scripts, etc.) have finished loading. The loadToc() function is probably used to perform some action or setup related to a table of contents or similar element on the page.

So in summary, when the page is fully loaded, the loadToc() function will be called.

Avatar of the person chatting

위 코드에서 dom 이 완전히 로드되어 있지 않으면 locadToc가 나오지 않는다. 어떻게 해야 할까?

위 코드는 페이지가 완전히 로드되어야만 loadToc() 함수가 실행됩니다.

만약 DOM이 완전히 로드되지 않은 상태에서 loadToc() 함수를 실행해야 하는 경우, DOMContentLoaded 이벤트를 사용할 수 있습니다. DOMContentLoaded 이벤트는 페이지의 DOM 트리가 로드되어 모든 요소에 액세스 할 수 있을 때 발생합니다.

아래와 같이 코드를 변경하시면 됩니다.

if (typeof window !== "undefined") { window.addEventListener("DOMContentLoaded", () => { loadToc(); }); }

이렇게 하면, DOMContentLoaded 이벤트가 발생하면 loadToc() 함수가 실행됩니다.

또는,

if (typeof window !== "undefined") { if (document.readyState === "complete" || (document.readyState !== "loading" && !document.documentElement.doScroll)) { loadToc(); } else { document.addEventListener("DOMContentLoaded", loadToc); } }

이렇게 하면, 만약 DOM이 이미 로드되어있다면, 즉시 loadToc() 함수를 실행하고, 그렇지 않다면 DOMContentLoaded 이벤트 리스너를 추가하여 loadToc() 함수를 실행합니다.