fork(1) download
  1. import java.util.*;
  2. import java.lang.*;
  3. import java.io.*;
  4. import java.util.regex.*;
  5.  
  6. class Ideone
  7. {
  8. public static void main (String[] args) throws java.lang.Exception
  9. {
  10. String text = "AAA-BBB-CCC-{AAA-BBB-AAA-BBB}-CCC-BBB-AAA";
  11. Pattern r = Pattern.compile("\\{[^{}]*}|(A)");
  12. Matcher m = r.matcher(text);
  13. String result = m.replaceAll(x -> x.group(1) != null ? "I" : x.group() );
  14. System.out.println( result );
  15. }
  16. }
Success #stdin #stdout 0.07s 33964KB
stdin
Standard input is empty
stdout
III-BBB-CCC-{AAA-BBB-AAA-BBB}-CCC-BBB-III