Advertisement
veronikaaa86

01. Match Full Name

Mar 15th, 2023
606
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.60 KB | None | 0 0
  1. package regularExpressions;
  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.         String regex = "\\b[A-Z][a-z]+ [A-Z][a-z]+\\b";
  14.         Pattern pattern = Pattern.compile(regex);
  15.         Matcher matcher = pattern.matcher(input);
  16.  
  17.         while (matcher.find()) {
  18.             String fullName = matcher.group();
  19.             System.out.print(fullName + " ");
  20.         }
  21.     }
  22. }
  23.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement