I need to match a javascript string, with a regular expression, that is a string enclosed by single quote and can only contain a backslashed single quote.
The exampl
Try this one:
/'(?:[^'\\]|\\'|\\(?!'))*'/
Test it in your console:
/'(?:[^'\\]|\\'|\\(?!'))*'/.exec("'abc\\\'de\\\'fg'")
It'll match
NOT ' or \ (except)\' (or)\ (not followed by ')If you want it to match the entire string, use the ^ start-of-string and $ end-of-string markers:
/^'(?:[^'\\]|\\'|\\(?!'))*'$/
... which will match 'string', 'string\'s are awesome' but not 'string's are awesome' or 'string's