English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
java.util.regexمكتبةPatternهذا النوع هو تمثيل التعبير النمطي بعد تجميعه.
هذا النوعtoString()يستخدم هذا الطريقة لتحويل تعبير النمطي الحالي إلى شكل نصي.
import java.util.Scanner; import java.util.regex.Pattern; public class Example { public static void main(String args[]) { //قراءة قيمة النص Scanner sc = new Scanner(System.in); System.out.println("أدخل نص الإدخال"); String input = sc.nextLine(); //البحث عن الأرقام باستخدام تعبير النمطي String regex = "(\\d)"; //تجميع تعبير النمطي Pattern pattern = Pattern.compile(regex); //طبع تعبير النمطي System.out.println("مكتبة التعبير النمطي المدمجة: " + pattern.toString()); //تحقق من whether there is a match if(pattern.matcher(input).find()) System.out.println("Given String contains digits"); else System.out.println("Given String does not contain digits"); } }
نتيجة الإخراج
أدخل سلسلة الإدخال This 7est contain5 di9its in place of certain charac7er5 تعبير منتظم معدير: (\d) Given String contains digits
import java.util.regex.Pattern; public class Example { public static void main(String args[]) { String regex = "w3codebox$"; String input = "Hi how are you welcome to w3codebox"; Pattern pattern = Pattern.compile(regex); Matcher match = pattern.matcher(input); int count = 0; if(match.find()) System.out.println("إيجاد مطابق"); else System.out.println("لم يتم العثور على مطابق"); System.out.println("التعبير المنتظم: " + pattern.toString()); } }
نتيجة الإخراج
إيجاد مطابق التعبير المنتظم: w3codebox$