Streaming live at 10am (PST)

Javascript regex error

Hello all,

I need to use subscript characters in certain words, and I thought it would be easiest to use regex to replace the characters after the page was rendered. This works, however it is still throwing error messages in the console. What is causing these error, and how can I avoid these?

I’m using this code in the footer section of the site:

<script>
jQuery(document).ready(function($){
    var pattern = RegExp(/\b(HydroSHEDSX)/g);
	var replaceWith = 'HydroSHEDS<sup>X</sup>'; 
	$("body").each(function(){
		$(this).html($(this).html().replace(pattern, replaceWith));
	});
});
</script>

the error message is this:

(index):4 Uncaught SyntaxError: Invalid regular expression flags
    at b (VM35 jquery-3.5.1.min.dc5e7f18c8.js:2)
    at Pe (VM35 jquery-3.5.1.min.dc5e7f18c8.js:2)
    at S.fn.init.append (VM35 jquery-3.5.1.min.dc5e7f18c8.js:2)
    at S.fn.init.<anonymous> (VM35 jquery-3.5.1.min.dc5e7f18c8.js:2)
    at $ (VM35 jquery-3.5.1.min.dc5e7f18c8.js:2)
    at S.fn.init.html (VM35 jquery-3.5.1.min.dc5e7f18c8.js:2)
    at HTMLBodyElement.<anonymous> ((index):42)
    at Function.each (VM35 jquery-3.5.1.min.dc5e7f18c8.js:2)
    at S.fn.init.each (VM35 jquery-3.5.1.min.dc5e7f18c8.js:2)
    at HTMLDocument.<anonymous> ((index):41)
VM35 jquery-3.5.1.min.dc5e7f18c8.js:2 jQuery.Deferred exception: e is not a function TypeError: e is not a function
    at r.define (https://uploads-ssl.webflow.com/5f45ccc2b5b5183eda63de16/js/webflow.c1c2aa10a.js:7:2938)
    at O (https://uploads-ssl.webflow.com/5f45ccc2b5b5183eda63de16/js/webflow.c1c2aa10a.js:7:4096)
    at Object.t.each.t.forEach (https://uploads-ssl.webflow.com/5f45ccc2b5b5183eda63de16/js/webflow.c1c2aa10a.js:38:553)
    at HTMLDocument.r.ready (https://uploads-ssl.webflow.com/5f45ccc2b5b5183eda63de16/js/webflow.c1c2aa10a.js:7:4443)
    at e (https://d3e54v103j8qbb.cloudfront.net/js/jquery-3.5.1.min.dc5e7f18c8.js?site=5f45ccc2b5b5183eda63de16:2:30005)
    at t (https://d3e54v103j8qbb.cloudfront.net/js/jquery-3.5.1.min.dc5e7f18c8.js?site=5f45ccc2b5b5183eda63de16:2:30307) undefined
S.Deferred.exceptionHook @ VM35 jquery-3.5.1.min.dc5e7f18c8.js:2
VM35 jquery-3.5.1.min.dc5e7f18c8.js:2 Uncaught TypeError: e is not a function
    at r.define (webflow.c1c2aa10a.js:7)
    at O (webflow.c1c2aa10a.js:7)
    at Object.t.each.t.forEach (webflow.c1c2aa10a.js:38)
    at HTMLDocument.r.ready (webflow.c1c2aa10a.js:7)
    at e (VM35 jquery-3.5.1.min.dc5e7f18c8.js:2)
    at t (VM35 jquery-3.5.1.min.dc5e7f18c8.js:2)

Here is my site Read-Only: LINK

I noticed the problem is in the replace clause:

var replaceWith = 'HydroSHEDS<sup>X</sup>'

The replace function interprets the forward slash as the start of the expression flag. I tried to escape it, but that didn’t work.

I’ve deactivated the script for now, as it breaks other functions, like lightbox etc.

If someone has an idea, I’d appreciate it.