Advertisement
veronikaaa86

01. Match Full Name

Nov 17th, 2021
329
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 regex = "\\b[A-Z][a-z]+ [A-Z][a-z]+\\b";
  12. String text = scanner.nextLine();
  13.  
  14. Pattern pattern = Pattern.compile(regex);
  15. Matcher matcher = pattern.matcher(text);
  16.  
  17. while (matcher.find()) {
  18. System.out.print(matcher.group() + " ");
  19. }
  20. }
  21. }
  22.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement