Regex escape forward slashes?

I’ve noticed that if I have an expression of the form,

test_B = (/Use of a scribe/word processing/i.test(importText));

…that the text editor always flags it as an error, unless I escape the forward slash:

test_B = (/Use of a scribe\/word processing/i.test(importText));

…and yet a forward slash is not normally a regex meta-character.

Is this correct?

Thank you,
Don

Hi Don,

as the forward slash is being seen as a pattern delimiter, you will have to escape the middle forward slash.
Otherwise the js-parser will see it as the end of your expression and therefore mark the remainder of the expression as being unexpected…

If you’re not comfortable doing this you can rewrite it this way:

var patt1 = new RegExp('Use of a scribe/word processing', 'i');
test_B = patt1.test(importText));

Thanks, Mark. That’s what I assumed, but wanted to confirm. - Don