Why doesn't `\d` work in regular expressions in sed?

user2036880 picture user2036880 · Feb 3, 2013 · Viewed 20.9k times · Source

I am trying to use \d in regex in sed but it doesn't work:

sed -re 's/\d+//g'

But this is working:

sed -re 's/[0-9]+//g'

Answer

Kamil picture Kamil · Feb 3, 2013

\d is a switch not a regular expression macro. If you want to use some predefined "constant" instead of [0-9] expression just try run this code:

s/[[:digit:]]+//g