Why does [^ \ d \ w \ s,] match "leonardo, davinci"?

I can not understand why regexp:

[^\d\s\w,]

Corresponds to the line:

"leonardo,davinci"

This is my test:

$ echo "leonardo,davinci" | egrep '[^\d\w\s,]'
leonardo,davinci

So far, this works as expected:

$ echo "leonardo,davinci" | egrep '[\S\W\D]'
$ 

Many thanks

+4
source share
1 answer

This is because egrepno predefined sets \d, \w, \s. Therefore, the old slash in front of them simply matches them literally:

Leonard d o , d avinci

echo "leonardo,davinci" | egrep '[^a-zA-Z0-9 ,]'

Really do not match.


If you installed it, you can use instead pcregrep:
echo "leonardo,davinci" | pcregrep '[^\w\s,]'
+9
source

All Articles