Jump to content

return reg ex in json responce

Go to solution Solved by vorticalbox,
RegExp.prototype.toJSON = RegExp.prototype.toString;

const myObj  = {
  reg: /(^|\s)[a-z]/g
}

console.log(JSON.stringify(myObj))

 

I have route that returns how a item should look, in which there is a field that contains regex. when I return that item be it as an object or JSON.stringify I just returns {} rather than the rex

 

here is an exmaple

 

https://repl.it/repls/FrigidSinfulZettabyte

 

basically how do I fix this? I am using NodeJS

                     ¸„»°'´¸„»°'´ Vorticalbox `'°«„¸`'°«„¸
`'°«„¸¸„»°'´¸„»°'´`'°«„¸Scientia Potentia est  ¸„»°'´`'°«„¸`'°«„¸¸„»°'´

Link to comment
https://linustechtips.com/topic/899072-return-reg-ex-in-json-responce/
Share on other sites

Link to post
Share on other sites

RegExp.prototype.toJSON = RegExp.prototype.toString;

const myObj  = {
  reg: /(^|\s)[a-z]/g
}

console.log(JSON.stringify(myObj))

 

                     ¸„»°'´¸„»°'´ Vorticalbox `'°«„¸`'°«„¸
`'°«„¸¸„»°'´¸„»°'´`'°«„¸Scientia Potentia est  ¸„»°'´`'°«„¸`'°«„¸¸„»°'´

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×