Languages

JavaScript - what is \W regex / '\w' and '\W' difference ?

3 points
Asked by:
Frida-Timms
667

What is \W (/\W/) regex and what is the difference between \w and \W?

1 answer
3 points
Answered by:
Admin Dirask Community
4380

\w/\w/ - matches any word character (shortcut for [a-zA-Z_0-9]).

\W - /\W/ - matches any character that is not a word character (shortcut for [^\w]).

 

Practical example that shows how to extract \w and \W characters from any string:

 

0 commentsAdd comment
Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.
Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join