-5

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

adrianbanks
  • 81,306
  • 22
  • 176
  • 206
Pablo.K
  • 1,041
  • 2
  • 10
  • 15

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

Joseph Didion
  • 142
  • 1
  • 6