I am trying to write a regex expression that will test if a given string has the following:
- single quote
- double quotes
- forward slash
- back slash
The string will be eventually coming from a JSON object.
here's what I have put together for testing purposes:
const validationRegex = new RegExp('[\'\"\\\/]+', 'g');
const name = `
myname\
`
let result = validationRegex.test(name)
console.log(result)
The result is "true" for the single quote, double quotes and forward slash which is the expected behavior. However for back slashes result is "false"
e.g.
const validationRegex = new RegExp('[\'\"\\\/]+', 'g');
const name = `
myname\
`
let result = validationRegex.test(name)
console.log(result) // false
What am I missing?