public class Test { /** * @param args */ public static void main(String[] args) { String mobile = "王二小(13112345678)"; // 调用 String endStr = removeStr(mobile); System.out.println("删除后结果:" + endStr); } public static String removeStr(String mobile) { String content = "张三(13312348888);王二小(13112345678);李四(13412345438);"; System.out.println("删除前:" + content); System.out.println("删除内容:" + mobile); String subContent = ""; if (!StringUtil.isBlank(content)) { mobile = mobile.replace("(", "\\("); mobile = mobile.replace(")", "\\)"); subContent = content.replaceAll(";" + mobile + "|" + mobile + ";", ""); } return subContent; } }
引用
输出如下:
删除前:张三(13312348888);王二小(13112345678);李四(13412345438); 删除内容:王二小(13112345678) 删除后结果:张三(13312348888);李四(13412345438);