开发者

Bash String Remove Specific Characters

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' 
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜