I'm almost done开发者_高级运维 with using bash, but the last thing I need to do is to do a regex replace on a string in bash. I have the PHP equivalent here
preg_replace("/[^a-z0-9\.]/", '',$theme_name);
I need to do this exact same thing in bash, which is replacing every non alphanumeric character or dots (.) with nothing. Thanks in advance!
Try the following:
echo "some string" | tr -d -c ".[:alnum:]"
tr
"translates" characters in the string-d
deletes instead of translates-c
means complement[:alnum:]
means "alpha numerics".
Try this
echo "hello world" | sed -e 's/[reg_ex]//g'
精彩评论