I have a regular expression that works when constructed via the native regex primitive:
var regex = /^(?:533-)?\d{3}-\d{4}$/;
'533-123-4567'.match(regex)
["533-123-4567", index: 0, input: "533-123-4567"]
but fails when it is constructed via a string:
var regex = new RegExp('/^(?:533-)?\d{3}-\d{4}$/');
'533-123-4567'.match(regex)
null
I have tried escaping the back slashes to no avail. Where is documentation on what characters must be escaped?