Tôi đang tìm cách thay thế một giá trị chuỗi java như sau. mã dưới đây không hoạt động.Regex sử dụng Java String.replaceAll
cleanInst.replaceAll("[<i>]", "");
cleanInst.replaceAll("[</i>]", "");
cleanInst.replaceAll("[//]", "/");
cleanInst.replaceAll("[\bPhysics Dept.\b]", "Physics Department");
cleanInst.replaceAll("[\b/n\b]", ";");
cleanInst.replaceAll("[\bDEPT\b]", "The Department");
cleanInst.replaceAll("[\bDEPT.\b]", "The Department");
cleanInst.replaceAll("[\bThe Dept.\b]", "The Department");
cleanInst.replaceAll("[\bthe dept.\b]", "The Department");
cleanInst.replaceAll("[\bThe Dept\b]", "The Department");
cleanInst.replaceAll("[\bthe dept\b]", "The Department");
cleanInst.replaceAll("[\bDept.\b]", "The Department");
cleanInst.replaceAll("[\bdept.\b]", "The Department");
cleanInst.replaceAll("[\bdept\b]", "The Department");
Cách dễ nhất để đạt được sự thay thế ở trên là gì?
bạn có ý nghĩa gì khi không hoạt động? – stinepike
Xóa các dấu ngoặc vuông ('[' và ']'). Đây là những lớp nhân vật. Nếu cái gì khác không hoạt động, bạn sẽ cần phải cụ thể hơn. – iamnotmaynard
Bạn có biết những gì một lớp nhân vật trong một regex? http://regex.info – fge