如何替换所有非字母数字字符&空格的空间? [英] How do I replace all non-alphanumerical characters & spaces with empty spaces?

查看:81
本文介绍了如何替换所有非字母数字字符&空格的空间?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何更换所有非字母数字字符&空格的空格?



我有这个但它只删除空格,我希望它删除所有非字母数字字符:



How do I replace all non-alphanumerical characters & spaces with empty spaces?

I have this but it only removes spaces, I want it to remove all NON-alphanumerical characters:

str.replaceAll("\\W","")







提前感谢您的帮助!





~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~



我尝试了什么:



str.replaceAll(\\\\,)





~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~




Thank you for the help in advance!


~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

What I have tried:

str.replaceAll("\\W","")


~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

推荐答案

尝试以下正则表达式



Try the following regular expression

[^a-zA-Z0-9]+



示例如下


The example follows

echo "abc---012" | sed -e 's/[^0-9a-zA-Z][^0-9a-zA-Z]*/ /g'
#output
abc 012





FYI:。+相当于.. *





FYI: .+ is equivalent to ..*

[^a-zA-Z0-9]



示例如下


example follows

echo "abc---012" | sed -e 's/[^0-9a-zA-Z]/ /g'
#output
abc   012


这篇关于如何替换所有非字母数字字符&空格的空间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆