import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Example {
public static void main(String[] args) {
final String regex = "([A-Z][A-Z|a-z|\\-|’|'|.]*( | - ))+([A-Z][A-Z|a-z|\\-|'|’|.]*)";
final String string = "Yashlin Hernandez Ortiz\n"
+ "Hanna King-Ashley\n"
+ "Jason Gray Jr.\n"
+ "Nate D. Ashabraner\n"
+ "James A Basham\n"
+ "J S Smith\n"
+ "T.J. Smith\n"
+ "K. P. Sifuentes\n"
+ "Dawn-Marie Spisak\n"
+ "Jenny Smith - Jones\n"
+ "D’leon Starnes\n"
+ "Joe Rowlings-pimentel\n"
+ "Jd Robinson\n"
+ "LJ Reighard\n"
+ "Seylin Ramirez-Collier Gomez\n"
+ "Isabel McCool-Bonilla\n"
+ "Gladys Lena Danie Kousok\n"
+ "Daniel De La Paz\n\n"
+ "One\n"
+ "One Two\n"
+ "One Two Three Four Five - Six ' Seven-eight Nine\n"
+ "Randy Bagwell and Corey Norris\n\n"
+ "Jenny Smith - Jones Ana and another Womwn In \n\n"
+ "Yashlin Hernandez Ortiz\n"
+ "Hanna King-Ashley\n"
+ "Jason Gray Jr.\n"
+ "Nate D. Ashabraner\n"
+ "James A Basham\n"
+ "J S Smith\n"
+ "T.J. Smith\n"
+ "K. P. Sifuentes\n"
+ "Dawn-Marie Spisak\n"
+ "Jenny Smith - Jones\n"
+ "D’leon Starnes\n"
+ "Joe Rowlings-pimentel\n"
+ "Jd Robinson\n"
+ "LJ Reighard\n"
+ "Seylin Ramirez-Collier Gomez\n"
+ "Isabel McCool-Bonilla\n"
+ "Gladys Lena Danie Kousok\n"
+ "Daniel De La Paz\n\n\n"
+ "Asummer like no other, students were consumed with whether or not their sport will have a season and how it will be different. The summer of questions and unknowns, kept students waiting.\n"
+ " When summer kicked off, students didn’t know how the season would look. Freshman Jaden Allen and other players walked to football practice the first day expecting to be getting gear to play and instead got a work out assigned. \n"
+ " “This season has been so different from past years,” Allen said. “We were not allowed any gear until Sept. 7 due to UIL guidelines. We did the entire summer without gear which was crazy.”\n"
+ " Volleyball players were told to wear masks and socially distance, as was tennis. \n"
+ " “It wasn’t a life-changing season like football, but it was different,” senior Lilly Taylor said. “Socially distancing on a small court is hard and a challenge to follow the guideline, but we made it work in order to practice.”\n"
+ " Band was not without shortcomings either. \n"
+ " “Our band camp was pushed back due to planning and how we were going to abide by the guidelines,” senior drum major Annie Mazon said. “The directors made sure to be on us about masks ensuring our safety and preserving our band season.” \n"
+ " The effect COVID-19 had on clubs and sports alike during the summer season helped students to enjoy what they had at the moment.\n"
+ " “I could not be more thankful to be back and have a possible season with my friends,” Mazon said.\n"
+ " Story by Ashlyn Vozeh\n\n"
+ " \n"
+ " \n"
+ " \n\n"
+ "Summer of Spikes \n"
+ "Coming back to practice after a break from COVID-19, players are eager to hit the court Aug. 18. Seniors Ashley Campbell and Hailey Huddleston were on the front line in a 6 vs. 6 scrimmage. “Our practices were a chance to catch up after so long and get ready for our season,” Huddleston said. “The feeling of getting to spike the ball again was amazing,” Photo by Ashlyn Vozeh\n\n"
+ "As band camp kicked off on Aug. 6, senior Hannah Sawyer leads her line of clarinets through the new band routine. “We had to wear masks during transitions and socially distance as much as possible during the season,” Sawyer said. “We were all just doing what we had to do in order to make this marching season the best one yet.” Photo by Claire Kennedy\n\n"
+ "“The famous Trumpeteers, Randy Bagwell and Corey Norris, practice their marching.”\n\n";
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