import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.*;
import java.lang.*;
import java.io.*;

class Ideone
{
	public static void main (String[] args) throws java.lang.Exception
	{
		String regex = "\\S.{0,39}(?<=\\S)(?!\\S)";
		String string = "abcd (efghij # / klmno (# #)\n"
			 + "blah blah etc etc words and more words and yet more words. What about these words?\n"
			 + "And some more text for this string so that we can test things out. ";
		
		Pattern pattern = Pattern.compile(regex);
		Matcher matcher = pattern.matcher(string);
		
		while (matcher.find()) {
		    System.out.println(matcher.group(0));
		}
	}
}