Intermediate Algorithm Scripting: Spinal Tap Case -- \W not matching underscore

For this challenge, I tried changing a line in the basic code solution and it didn’t work though it seems like it should. Here’s my current code:

function spinalCase(str) {

  // Create a variable for the white space and underscores.
  var regex = /\W/g; <-- the part I changed

  // Replace low-upper case to low-space-uppercase
  str = str.replace(/([a-z])([A-Z])/g, '$1 $2');

  // Replace space and underscore with -
  return str.replace(regex, '-').toLowerCase();
}

console.log(spinalCase('The_Andy_Griffith_Show'));

I changed var regex = /\s+|_+/g; as provided in the solution to var regex = /\W/g;, which seemed like it would work the same way since the metacharacter \W (which matches nonalphanumeric characters) should match an underscore. However, with my change, the console log for spinalCase('The_Andy_Griffith_Show') outputs the_andy_griffith_show. Changing it to var regex = /\W|_/g; passes all the tests, so matching the underscore does seem to be the issue. Any ideas?

I would advise reading what \w/\W matches. (it matches a word character, and a word in this context is a thing that is used as an identifier in a programming language)