-5

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

adrianbanks
  • 79,167
  • 22
  • 173
  • 203
Pablo.K
  • 881
  • 1
  • 8
  • 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