Page 213 - 6253
P. 213

import java.util.regex.Matcher;

                  import java.util.regex.Pattern;



                  public class Main {



                      public static boolean test1(String testString) {

                          Pattern p = Pattern.compile("^JAVA$");

                          Matcher m = p.matcher(testString);

                          return m.matches();

                      }

                      public static boolean test2(String testString) {

                          Pattern p = Pattern.compile(".+\\.(com|ua|ru)");

                          Matcher m = p.matcher(testString);


                          return m.matches();
                      }


                      public static void main(String[] args) {

                          System.out.println(test1("JAVA"));   //true

                          System.out.println(test1("  JAVA"));   //false

                          System.out.println(test1("JAVA  "));   //false

                          System.out.println(test1("^JAVA$"));  //false

                          System.out.println(test1("java"));   //false



                          System.out.println(test2("trololo.com"));   //true

                          System.out.println(test2("trololo.ua ")); //false

                          System.out.println(test2("trololo.ua"));  //true

                          System.out.println(test2("trololo/ua"));  //false

                          System.out.println(test2("i love site java.ua"));  //true

                          System.out.println(test2("JAVA.ru"));      //true


                          System.out.println(test2("JAVA.de"));      //false

                      }

                  }


                                                              212
   208   209   210   211   212   213   214   215   216   217   218