fork(1) download
  1. import java.util.*;
  2. import java.util.regex.*;
  3.  
  4. class Ideone
  5. {
  6. public static void main (String[] args) throws java.lang.Exception
  7. {
  8. String s = "I|123|\"hi\"\nU|321|\"ola\"\nD|098|\"welcome \n to the hotel \n california\"\nI|234|\"ya!\"";
  9. Pattern p = Pattern.compile("\"[^\"]*\"");
  10. StringBuffer result = new StringBuffer();
  11. Matcher m = p.matcher(s);
  12. while (m.find()) {
  13. m.appendReplacement(result, m.group().replaceAll("\n+", " "));
  14. }
  15. m.appendTail(result);
  16. System.out.println(result.toString());
  17.  
  18. }
  19. }
Success #stdin #stdout 0.07s 48036KB
stdin
Standard input is empty
stdout
I|123|"hi"
U|321|"ola"
D|098|"welcome   to the hotel   california"
I|234|"ya!"