Troubleshooting creating a single page application. Browser does not include in DOM CDATA javascript blocks

What i’ve got is quite a rare situation. At my current company, we are making some changes to an existing web application to transform it to a singlepage one. Our current approach is to request and render each page through Jquery’s AJAX’s implementation, but we found a very weird behaviour here. If we access the…

javascript how to regex match and replace on hashtags but exclude the hashtag character

I have the following function: function formattedTitle(posttitle,hreflink) { return `<a href=’`+ hreflink +`’>` + posttitle.replace(/(^|\s)(#[-.\w]+)/gi, `$1</a><a class=”hashtag” href=’/search?q=hashtag:”$2″‘>$2</a><a href=’`+ hreflink + `’>`) + ‘</a>’; } When I run console.log(formattedTitle(‘This is #awesome news’,’google.com’)); It outputs: <a href=’google.com’>This is </a><a class=”hashtag” href=’/search?q=hashtag:”#awesome”‘>#awesome</a><a href=’google.com’> news</a> Notice how it includes the “#” in the $2 match. How can I…