[英]What is the Regular Expression for special characters (everything except digits & alphabets) in java
I wish to convert all the special characters(everything except digits & alphabets) to the character '*' by using replaceAll() 我想通过使用replaceAll()将所有特殊字符(除数字和字母之外的所有字符)转换为字符'*'
string2=string1.replaceAll("[RegX]", "*")
What shall I write in place of RegX ? 我应该用什么来代替RegX ?
The following should work : \\W
. 以下应该有效:
\\W
It matches anything other than a letter, digit or underscore. 它匹配除字母,数字或下划线以外的任何内容。
We just need to add the _
to pick it up also. 我们只需要添加
_
来拾取它。
string2 = string1.replaceAll("[\\W_]", "*")
正则表达式"[^\\\\p{IsLatin}\\\\p{Digit}]"
还将识别特定于语言的字符,例如œŒŸÉÑÜÚÓöÄß
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.