代码如下: import java.util.regex.*
// 表达式对象
Pattern p = Pattern.compile("[\\\'\\*\\~]")
// 创建 Matcher 对象
Matcher m = p.matcher("String str = \"t\'e*s~t\" ")
// 替换
String newstring = m.replaceAll("[$0]")
效果如下:
正则参考 http://zh.wikipedia.org/wiki/%E6%AD%A3%E5%88%99%E8%A1%A8%E8%BE%BE%E5%BC%8F
String regEx="[A-Z,a-z,0-9,-]*"boolean result=Pattern.compile(regEx).matcher(str).find()