English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

تعبير النمط "\ Z" في Java

التعبير الفرعي/الرمز "\ Z" يتطابق مع نهاية النص الكامل، باستثناء نهاية السطر المسموح بها.

مثال 1

import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class RegexExample {
   public static void main( String args[] ) {
      String regex = "w3codebox\\z";
      String input = "Hi how are you welcome to w3codebox";
      Pattern p = Pattern.compile(regex);
      Matcher m = p.matcher(input);
      int count = 0;
      while(m.find()) {
         count++;
      }
      System.out.println("عدد التطابقات: " + count);
   }
}

نتيجة الخروج

عدد التطابقات: 1

مثال 2

هذا البرنامج Java يتحقق مما إذا كان النص المدخل ينتهي بالرقم.

import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Data {
   public static void main( String args[] ) {
      String regex = "[0-9]\\z";
      String input = "Hi how are you 
 this is sample text 
 this is third line 554";
      Pattern p = Pattern.compile(regex);
      Matcher m = p.matcher(input);
      if(m.find()) {
         System.out.println("إذا كان المدخل ينتهي بالرقم");
      } else {
         System.out.println("إذا كان المدخل لا ينتهي بالرقم");
      }
   }
}

نتيجة الخروج

إذا كان المدخل ينتهي بالرقم
الشئ الذي قد يعجبك