-3

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?

androideka
  • 71
  • 1
  • 11

1 Answers1

0

You could write it as...

String str2 = str1.replaceAll("[BC]", "");
alex
  • 479,566
  • 201
  • 878
  • 984