문제

I have the following String:

String str1= "ABCD";

I want the following String

String str2 = "AD"

Therefore, I would like something along the lines of this:

String str2 = str1.replaceAll("/* SOME REGEX HERE */", "");

How can I write the regex so that both "B" and "C" are replaced?

도움이 되었습니까?

해결책

You could write it as...

String str2 = str1.replaceAll("[BC]", "");
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top