English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
java.util.regex.Matcher هي كائن محرك لتنفيذ عمليات التطابق المختلفة. لا تحتوي هذه الفئة على مُهندس، ويمكن إنشاء/الحصول على كائن من هذه الفئة باستخدام طريقة matchs() من الفئة java.util.regex.Pattern.
فئة (Matcher) هذهregion()يقبل هذا الدالة إدخال أرقامين كاملين يمثلان موقعين في نص الإدخال ويضبط منطقة المُطابق الحالي.
import java.util.Scanner; import java.util.regex.Matcher; import java.util.regex.Pattern; public class RegionExample { public static void main(String[] args) { //Regular expression to accepts 6 to 10 characters String regex = "\\A(?=\\w{6,10}\\z)"; System.out.println("Enter 5 to 12 characters:"); String input = new Scanner(System.in).next(); //Creating a pattern object Pattern pattern = Pattern.compile(regex); //Creating a Matcher object Matcher matcher = pattern.matcher(input); //Setting region to the input string matcher.region(0, 4); //Switching to transparent bounds if(matcher.find()) { System.out.println("تم العثور على تطابق"); } else { System.out.println("لم يتم العثور على تطابق"); } } }
نتائج الإخراج
ادخل 5 إلى 12 حرفًا: sampleText لم يتم العثور على تطابق
import java.util.regex.Matcher; import java.util.regex.Pattern; public class RegionExample { public static void main(String[] args) { String regex = "(.*)(\\d+)(.*)"; String input = "This is a sample Text, 1234, with numbers in between."; //Creating a pattern object Pattern pattern = Pattern.compile(regex); //Creating a Matcher object Matcher matcher = pattern.matcher(input); //Setting the region of the matcher matcher.region(0, 20); if(matcher.matches()) { System.out.println("تم العثور على تطابق"); } else { System.out.println("لم يتم العثور على تطابق"); } } }
نتائج الإخراج
لم يتم العثور على تطابق