সাবএক্সপ্রেশন/মেটাচ্যারেক্টার “\Z” সম্পূর্ণ স্ট্রিং এর শেষের সাথে মেলে, বাদে অনুমোদিত ফাইনাল লাইন টার্মিনেটর।
উদাহরণ 1
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class RegexExample {
public static void main( String args[] ) {
String regex = "Tutorialspoint\\z";
String input = "Hi how are you welcome to Tutorialspoint";
Pattern p = Pattern.compile(regex);
Matcher m = p.matcher(input);
int count = 0;
while(m.find()) {
count++;
}
System.out.println("Number of matches: "+count);
}
} আউটপুট
Number of matches: 1
উদাহরণ 2
নিম্নলিখিত জাভা প্রোগ্রামটি যাচাই করে যে প্রদত্ত ইনপুট পাঠ্যটি একটি সংখ্যা দিয়ে শেষ হয় কিনা৷
৷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 \n this is sample text \n this is third line 554";
Pattern p = Pattern.compile(regex);
Matcher m = p.matcher(input);
if(m.find()) {
System.out.println("Given input ends with a digit");
} else {
System.out.println("Given input doesn’t end with a digit");
}
}
} আউটপুট
Given input ends with a digit