Question

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?

Was it helpful?

Solution

You could write it as...

String str2 = str1.replaceAll("[BC]", "");
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top