正则表达式常用

1.去除小括号以及小括号中的内容

str.replaceAll("\\([^)]*\\)","")

2.去除中括号及中括号中的内容

str.replaceAll("\\[[^]]*\\]", "")

3.将所有非数字替换为空格

str.replaceAll("[^\\w]", " ")

4.替换各种乱七八糟的符号为空格,按空格拆分

String[] tmpwords = title.replaceAll("[\\(|\\)|\\{|\\}|\\[\\]|,|/]"," ").split(" ");


你可能感兴趣的:(正则表达式常用)