Guest User

Untitled

a guest
May 27th, 2018
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.03 KB | None | 0 0
  1. import java.util.regex.Matcher;
  2. import java.util.regex.Pattern;
  3.  
  4. public class Regex {
  5. public static void main(String[] args) {
  6.  
  7. String schools = "Name: Hillel, City: Odessa; Name: Stanford, City: Stanford";
  8.  
  9. // System.out.println(schools.matches(".*__.*"));
  10.  
  11. // System.out.println(schools.replaceAll("Name: ([^,]+)", "Name: *$1*"));
  12. // System.out.println(schools);
  13.  
  14. String text = "Hello, my name is\n Robert. I am a programmer.";
  15. String betterText = text.toLowerCase().replaceAll("[.,!?;:]", "");
  16. // System.out.println(betterText);
  17. String[] words = betterText.split("\\s+");
  18. // for (String w : words) {
  19. // System.out.println(w);
  20. // }
  21.  
  22. String phoneNumber = "+380975156900";
  23.  
  24. Pattern myRegex = Pattern.compile(".{3}(.{3})");
  25.  
  26. Matcher m = myRegex.matcher(phoneNumber);
  27. if (m.find()) {
  28. System.out.println(m.group());
  29. } else {
  30. System.out.println("No carrier code in phone number.");
  31. }
  32.  
  33. }
  34. }
Add Comment
Please, Sign In to add comment