Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
-2
rated 0 times [  4] [ 6]  / answers: 1 / hits: 29400  / 12 Years ago, fri, february 1, 2013, 12:00:00
var badCode = (INST1,\[0,;
var regex = new RegExp(badCode, igm);


gets unterminated character class error.



How to fix?



TIA



trying suggestions from responders to this post, please see the following screen prints (you might have to right-click on images and open in new tab to make legible):
note values of new_bad_thing (equiv of badCode above)



and here is the screen print when I hit the run button (please note the error message):



enter


More From » regex

 Answers
103

Put another backslash at badCode:



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


since you need one to escape ( inside the regex itself (signal it that it's a literal parentheis) and one escape for javascript.


[#80489] Wednesday, January 30, 2013, 12 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
daijac

Total Points: 568
Total Questions: 120
Total Answers: 108

Location: Virgin Islands (U.S.)
Member since Fri, May 7, 2021
3 Years ago
;