Take the 2-minute tour ×  I'm writing a rudimentary lexer using
regular expressions in JavaScript and I have two regular
expressions (one for single quoted strings and one for double
quoted strings) which I wish to combine into one. These are my
two regular expressions (I added the ^ and $ characters for
testing purposes):  var singleQuotedString = /^'(?:[^'\\]|\\'|\\
\\|\\\/|\\b|\\f|\\n|\\r|\\t|\\u[0-9A-F]{4})*'$/gi; var
doubleQuotedString = /^"(?:[^"\\]|\\"|\\\\|\\\/|\\b|\\f|\\n|\\r|
\\t|\\u[0-9A-F]{4})*"$/gi;  Now I tried to combine them into a
single regular expression as follows:  var string = /^(["'])(?:[
^\1\\]|\\\1|\\\\|\\\/|\\b|\\f|\\n|\\r|\\t|\\u[0-9A-
F]{4})*\1$/gi;  However when I test the input "Hello"World!" it
returns true instead of false:
alert(string.test('"Hello"World!"')); //should return false as a
double quoted string must escape double quote characters  I
figured that the problem is in [^\1\\] which should match any
character besides \1 (which is either a single or a double quote
- the del