-5

What is this RegEx /[\W_]/g in JavaScript? I know the \W locates non-word characters, but what does the _ do?

adrianbanks
  • 76,725
  • 21
  • 166
  • 198
Pablo.K
  • 761
  • 1
  • 7
  • 13

1 Answers1

0

The whole regex string will match anything that is not letters and numbers

It is the same as [^a-zA-Z0-9]

The \W is included: (as you said) matches non word characters

the _ is included so it matches the literal underscore character that wouldn't be accepted in \W