import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Example {
public static void main(String[] args) {
final String regex = "(?s)\\b[A-Z]\\..*?\\?(?=\\h+[A-Z]\\.|$)";
final String string = "A. What sort of country do the framers of the Northwest Ordinance envision for the next generation of Americans?\n"
+ "B. How do the statements on behalf of individual religious rights and the public support of religion compare with the statements found in the new state constitutions?\n\n"
+ "A. What explains President Lincoln’s attitude toward Louisiana in his letter to General Banks? Does his Second Inaugural Address explain his attitude? How do Lincoln, Douglass, and Stevens’ attitudes toward the South differ? Is Stevens’ constitutional argument about the basis of Reconstruction sound? If so, was that sufficient to make his approach to the seceded states sound? Do Stevens’ remarks about Jews, the Irish and others undermine his claim to be a champion of the principles of the Declaration of Independence? Was the response of Southerners as described and defended by Tillman inevitable, or could some version of restoration or reconstruction have prevented it?\n"
+ "B. Do the views expressed in the twentieth century differ from those expressed in the documents below? For example, compare the views of Senators Tillman and Thurmond, both Democrats from South Carolina. Did the constitutional arguments change between the 1860s and the 1960s?\n"
+ "C. How true does President Abraham Lincoln’s remark in his Second Inaugural Address that both Northerners and Southerners prayed to the same God and read the same Bible appear in light of the very different interpretations of said Bible on the question of slavery, as evidenced in the antebellum period?\n\n"
+ "test A.Test? B.Test?";
final Pattern pattern = Pattern.compile(regex, Pattern.MULTILINE);
final Matcher matcher = pattern.matcher(string);
while (matcher.find()) {
System.out.println("Full match: " + matcher.group(0));
for (int i = 1; i <= matcher.groupCount(); i++) {
System.out.println("Group " + i + ": " + matcher.group(i));
}
}
}
}
Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for Java, please visit: https://docs.oracle.com/javase/7/docs/api/java/util/regex/Pattern.html