import java.util.regex.*; import java.io.*; public class MultipleFlag{ public static void main(String[] args){ String inputStr = "Abc\ndef"; //Simply print the original string. System.out.println(inputStr); String patternStr = "\n"; // Compile with multiline and case-insensitive enabled. Pattern pattern = Pattern.compile(patternStr, Pattern.MULTILINE | Pattern.CASE_INSENSITIVE); Matcher matcher = pattern.matcher(inputStr); //Finding new line and replacing with a tab. boolean matchFound = matcher.find(); String str = matcher.replaceAll("\t"); System.out.println(matchFound); System.out.println(str); //Split from where the new line character lies in the string. String[] strg = "Abc\ndef".split("\n"); for (int i =0; i