HYPE Javascript and REGEX

(Andrew) #1

Is there any reason why i would get an error when using regular expressions on a string:

message: “Unexpected token ‘/’. Invalid regular expression.”

element.innerHTML = element.innerHTML.replace(/<strong>/g, ''); element.innerHTML = element.innerHTML.replace(/</strong>/g, '');

(Hans-Gerd Claßen) #2

you’ve got to escape the regular expression metacharacters …
in this case/</strong>/g

(Andrew) #3

Thanks, knew it would have been something I missed. :smile: