Skip to content

can't return regex as string due to serialization #3237

Answered by IvanGoncharov
Chathula asked this question in Q&A
Discussion options

You must be logged in to vote

@Chathula Both JSON and Node's inspect add slash but it doesn't exist in string itself and you can check this using console.log:

new RegExp(/\d{3}(-?|\s?)\d{3}/).toString()
// '/\\d{3}(-?|\\s?)\\d{3}/'

console.log(new RegExp(/\d{3}(-?|\s?)\d{3}/).toString())
// /\d{3}(-?|\s?)\d{3}/

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by saihaj
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
2 participants
Converted from issue

This discussion was converted from issue #2497 on August 13, 2021 03:59.