Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

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?

share|improve this question

closed as too localized by nhahtdh, Reimeus, Jarrod Roberson, fglez, Andremoniy Apr 10 '13 at 9:16

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center.If this question can be reworded to fit the rules in the help center, please edit the question.

    
Do you mean to replace all characters between A and D? Between the first and the last? Your problem is ambiguous. –  Patashu Apr 10 '13 at 2:43
    
I want to know how to replace any two characters with "". –  androideka Apr 10 '13 at 2:47
    
@androideka sorry to ask, but can you undelete your last question (time difference in Java/Android)? I already have prepared an answer. –  Luiggi Mendoza Apr 10 '13 at 21:18

1 Answer 1

up vote 0 down vote accepted

You could write it as...

String str2 = str1.replaceAll("[BC]", "");
share|improve this answer

Not the answer you're looking for? Browse other questions tagged or ask your own question.