import java.util.Scanner; import java.util.regex.Matcher; import java.util.regex.Pattern; public class StringsBetweenQuotes { public static void main(String[] args) { Scanner sc = new Scanner(System.in); System.out.println(\"Enter a string: \"); String str = sc.nextLine(); //Close scanner sc.close(); //Regex String regex = \"\\\"((?:\\\\\\\\.|[^\\\"])*)\\\"\"; Pattern patt = Pattern.compile(regex); Matcher matcher = patt.matcher(str); int start = 0; while(matcher.find(start)) { String outputStr = matcher.group(1); System.out.println(outputStr); start = matcher.end(1) + 1; } } } SAMPLE OUTPUT: Enter a string: No strings on this line. Enter a string: Two \"quoted strings\" in \"this line\". quoted strings this line Enter a string: This string \"contains an \\\" escaped quote mark\". contains an \\\" escaped quote mark Enter a string: This string \"contains \\a \\b \\c \\d a bunch of escaped\" characters contains \\a \\b \\c \\d a bunch of escaped Enter a string: No strings \"on this line either Enter a string: This is \\\"a tricky one\" a tricky one Enter a string: So is \"this one\\ Enter a string: \" Solution import java.util.Scanner; import java.util.regex.Matcher; import java.util.regex.Pattern; public class StringsBetweenQuotes { public static void main(String[] args) { Scanner sc = new Scanner(System.in); System.out.println(\"Enter a string: \"); String str = sc.nextLine(); //Close scanner sc.close(); //Regex String regex = \"\\\"((?:\\\\\\\\.|[^\\\"])*)\\\"\"; Pattern patt = Pattern.compile(regex); Matcher matcher = patt.matcher(str); int start = 0; while(matcher.find(start)) { String outputStr = matcher.group(1); System.out.println(outputStr); start = matcher.end(1) + 1; } } } SAMPLE OUTPUT: Enter a string: No strings on this line. Enter a string: Two \"quoted strings\" in \"this line\". quoted strings this line Enter a string: This string \"contains an \\\" escaped quote mark\". contains an \\\" escaped quote mark Enter a string: This string \"contains \\a \\b \\c \\d a bunch of escaped\" characters contains \\a \\b \\c \\d a bunch of escaped Enter a string: No strings \"on this line either Enter a string: This is \\\"a tricky one\" a tricky one Enter a string: So is \"this one\\ Enter a string: \".