//提取数字 public String numberintercept(String num) { String phoneString =num; Pattern pattern = Pattern.compile("[^0-9]"); Matcher matcher = pattern.matcher(phoneString); String all = matcher.replaceAll(""); return Pattern.compile("[^0-9]").matcher(phoneString).replaceAll(""); }
<span style="white-space:pre"> </span>//提取汉字 public String intercept(String str) { String regex = "[\u4E00-\u9FA5]+";// [//u4E00-//u9FFF]为汉字 Pattern pattern = Pattern.compile(regex); Matcher matcher = pattern.matcher(str); StringBuffer sb = new StringBuffer(); while (matcher.find()) { sb.append(matcher.group()); } String content = sb.toString(); return content; }
<span style="white-space:pre"> </span>//过滤不想要的特殊符号 public String con (String str) { String regEx="[`~!@#$%^&*()+=|{}:;\\[\\].<>/?~!@#¥%……&*()——+|{}【】‘;:”“’。,、?]"; Pattern p = Pattern.compile(regEx); Matcher m = p.matcher(str); String url = m.replaceAll("").trim(); return url; }