Javascript unterminated character class

var badCode = "\(INST1,\\[0,";
var regex = new RegExp(badCode, "igm");

gets the error "unterminated character class".

How to fix?

TIA

Having tried the suggestions from the respondents for this post, look at the following screenshots (you may need to right-click on the images and open in a new tab to make it legible): check the values โ€‹โ€‹of new_bad_thing (equiv of badCode above)

and here is the screen print when I press the start button (note the error message):

enter image description here

+5
source share
2 answers

Put another backslash in badCode:

var badCode = "\\(INST1,\\[0,";
var regex = new RegExp(badCode, "igm");

( ( , ) escape javascript.

+6

, "unterminated ", . ?

var regex = /\(INST1,\[0,/igm;
+3

All Articles