\w
- represents the character class [A-Za-z0-9_]
Character class
Despite this, I find it difficult to grasp how it is interpreted within a character class.
When I use
[\w-~]
let test = (str) => /^[\w-~]+$/.test(str)
console.log(test("T|"))
it fails for T|
However, if I use
[A-Za-z0-9_-~]
let test = (str) => /^[A-Za-z0-9_-~]+$/.test(str)
console.log(test("T|"))
it returns true,
I am puzzled by how these two expressions differ from each other?