English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
المحرف النموذجي “$” يطابق نهاية النص المحدد، أي أنه يطابق آخر حرف في النص. على سبيل المثال،
عبرة “ \\ d $
عبرة “ [az] $ ”مطابق ينتهي بحرف صغير. "
إدراج java.util.Scanner; import java.util.regex.Matcher; import java.util.regex.Pattern; public class Example { public static void main(String args[]) { //قراءة النص من المستخدم System.out.println("أدخل نصًا"); Scanner sc = new Scanner(System.in); String input = sc.nextLine(); String regex = ".*[^a-zA-Z0-9//s]$"; //تجميع التعبير العادي Pattern pattern = Pattern.compile(regex); //استرجاع ملاحظة التطابق Matcher matcher = pattern.matcher(input); if(matcher.matches()) { System.out.println("حدث التطابق"); } else { System.out.println("لم يحدث التطابق"); } } }
أدخل نصًا هذا نص مثال # حدث التطابق
أدخل نصًا مرحبًا كيف حالك لم يحدث التطابق
إدراج java.util.Scanner; import java.util.regex.Matcher; import java.util.regex.Pattern; public class RegexExample { public static void main( String args[] ) { String regex = "\\.$"; Scanner sc = new Scanner(System.in); System.out.println("Enter 5 input strings:"); String input[] = new String[5]; for (int i = 0; i < 5; i++) { input[i] = sc.nextLine(); } // create a Pattern object Pattern p = Pattern.compile(regex); for(int i = 0; i < 5; i++) { // create a Matcher object Matcher m = p.matcher(input[i]); if(m.find()) { System.out.println("String " + i + " ends with '.'"); } } } }
النتيجة الصادرة
Enter 5 input strings: hello how are you. where do you live what is your name. welcome to w3codebox The Biggest Online Tutorials Library. String 0 ends with '.' String 2 ends with '.' String 4 ends with '.'