SyntaxError: invalid regular expression: missing /

According to http://www.regexr.com/38o5d my reqex seems to work, but when I implement it in my javascript

var prefix = hash.replace(/\/|#/g, '');

I will get the following error: SyntaxError: Invalid regex: missing /

+8
javascript regex
source share
1 answer

Mental debugging: your code is not in plain JavaScript or HTML file, but is printed from a scripting language in which # is a comment symbol. Part #/g, ''); treated as a comment in your script.

You need to add some quotation marks to ensure that the entire line is printed.

+9
source share

All Articles