You can pass aa custom replace function toJSON.stringify and convert the regular expression to a string (assuming that this expression is part of an array or object):
JSON.stringify(value, function(key, value) {
if (value instanceof RegExp) {
return value.toString();
}
return value;
});
If you really do not want / should not create JSON, just call the toString()expression method .
source
share