fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.regex.*;
  4.  
  5. /* Name of the class has to be "Main" only if the class is public. */
  6. class Ideone
  7. {
  8. public static void main (String[] args) throws java.lang.Exception
  9. {
  10. String str =
  11. "I found a street animal. It was a dog. \r\nThen the dog found another dog. \r\nIt was kind of fun to see the two dogs barking to each other.";
  12.  
  13. Pattern pattern = Pattern.compile("(?<=dog\\.(?!\\s*\\n))\\s*");
  14. Matcher matcher = pattern.matcher(str);
  15. System.out.println( matcher.replaceAll("\r\n") );
  16.  
  17. System.out.println( "============================" );
  18.  
  19. str =
  20. "I found a street animal. It was a dog. Then the dog found another dog. It was kind of fun to see the two dogs barking to each other.";
  21. pattern = Pattern.compile("(?<=dog\\.(?!\\s*\\n))\\s*");
  22. matcher = pattern.matcher(str);
  23. System.out.println( matcher.replaceAll("\r\n") );
  24.  
  25. }
  26. }
Success #stdin #stdout 0.1s 320576KB
stdin
Standard input is empty
stdout
I found a street animal. It was a dog. 
Then the dog found another dog. 
It was kind of fun to see the two dogs barking to each other.
============================
I found a street animal. It was a dog.
Then the dog found another dog.
It was kind of fun to see the two dogs barking to each other.