الكتابة المقيدة Java 41- Regular expressions- Matcher and Pattern class

في هذا الفيديو من جافا JAVA, سنتحدث عن التعبيرات النمطية , اي كيفية تحديد نمط ادخال البيانات من طرف المستخدم, اي كيف نجبره على ادخال البريد الالكتروني او رقم الهاتف او كلمة السر دون غيرها من البيانات. Regular expressions- Matcher and Pattern class


package package3;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Apple {

    /*
     * static boolean matches(String regex, CharSequence input)
     * static Pattern compile(String regex)
     * Matcher matcher(CharSequence input)
     * boolean find()
     * int start()
     * int end()
     */
       
    public static void main(String[] args) {
        
        System.out.println(Pattern.matches("Mo.d", "Moad"));
        System.out.println(Pattern.matches("Mo*ad", "Mooooad"));

        //créer un motif à trouver
        Pattern patt= Pattern.compile("[aA]itaayi$");

        //trouver le motif ci-dessus dans "moad aitaayi" 
        Matcher match= patt.matcher("moad aitaayi");
        
        //afficher l'index de début et fin du motif dans "moad aitaayi" 
      while (match.find()) {
        System.out.println("start "+match.start()+" end "+(match.end()-1));
      }

    }
}

affiche : 
         true
         true
         start 5 end 11