veronikaaa86

01. Match Full Name

Jul 20th, 2022 (edited)
207
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.55 KB | None | 0 0
  1. package regex;
  2.  
  3. import java.util.Scanner;
  4. import java.util.regex.Matcher;
  5. import java.util.regex.Pattern;
  6.  
  7. public class P01MatchFullName {
  8. public static void main(String[] args) {
  9. Scanner scanner = new Scanner(System.in);
  10.  
  11. String input = scanner.nextLine();
  12.  
  13. Pattern pattern = Pattern.compile("\\b[A-Z][a-z]+ [A-Z][a-z]+\\b");
  14. Matcher matcher = pattern.matcher(input);
  15.  
  16. while (matcher.find()) {
  17. String name = matcher.group();
  18. System.out.print(name + " ");
  19. }
  20. }
  21. }
  22.  
Add Comment
Please, Sign In to add comment