I am trying to validate some inputs to remove a set of characters. Only alphanumeric characters plus, period, underscore, hyphen are allowed. I've tested the regex expression [^\w.-]
here http://gskinner.com/RegExr/ and it matches what I want removed so I not sure why sed
is returning the opposite. What am I missing?
My end goal is to input "Â10.41.89.50 "
and get "10.41.89.50
".
I've tried:
echo "Â10.41.89.50 " | sed s/[^\w.-]//g
returns Â...
echo "Â10.41.89.50 " | sed s/[\w.-]//g
and echo "Â10.41.89.50 " | sed s/[\w^.-]//g
returns Â10418950
I attempted the answer found here Skip/remove non-ascii character with sed but nothing was removed.
-r
option tosed
so it will recognize extended regular expressions. – Barmarsed
doesn't understand the special character classes like\w
. Just use[a-zA-Z0-9_-]
. – Mark Reed-r
nor using[a-zA-Z0-9_-]
works. Wellecho "Â10.41.89.50 " | sed s/[a-zA-Z0-9.-]//g
returnedÂ
butecho "Â10.41.89.50 " | sed s/[^a-zA-Z0-9.-]//g
still returnedÂ10.41.89.50
. – wanderingandy