Guest User

Untitled

a guest
Jan 19th, 2019
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.14 KB | None | 0 0
  1. Matcher matches = Pattern.compile("T\d+").matcher("T234bird");
  2. System.out.println(matches.lookingAt()); //after running this, find() will return false
  3. while (matches.find())
  4. System.out.println(matches.group());
  5. //Output: true
  6.  
  7. Matcher matches = Pattern.compile("T\d+").matcher("T234bird");
  8. //System.out.println(matches.lookingAt()); //without this, find() will return true
  9. while (matches.find())
  10. System.out.println(matches.group());
  11. //Output: T234
  12.  
  13. Matcher matches = Pattern.compile("T\d+").matcher("T234bird");
  14. while (matches.lookingAt())
  15. System.out.println(matches.group());
  16. //Output: T234 T234 T234 T234 ... till crash
  17. //I understand why this happens. It's not my question but I just included it in case someone may try to suggest it
  18.  
  19. Matcher matches = Pattern.compile("T\d+").matcher("T234bird");
  20. if(matches.lookingAt())
  21. System.out.println(matches.group());
  22. //Output: T234
  23.  
  24. Matcher matches = Pattern.compile("T\d+").matcher("T234bird");
  25. if (matches.lookingAt())
  26. System.out.println(matches.group());
  27.  
  28. Matcher matches = Pattern.compile("^T\d+").matcher("T234bird");
  29. if (matches.find())
  30. System.out.println(matches.group());
Add Comment
Please, Sign In to add comment