সাবএক্সপ্রেশন/মেটাক্যারেক্টার "\z" স্ট্রিংয়ের আসলো৫ এন্ড ম্যাচ করে (লাইন টার্মিনেটরও উপেক্ষা করে)।
উদাহরণ ১: "Tutorialspoint" দিয়ে শেষ
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("ম্যাচের সংখ্যা: " + count);
}
}
আউটপুট
ম্যাচের সংখ্যা: 1
উদাহরণ ২: মাল্টিলাইন ইনপুটের শেষে ডিজিট
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("দেওয়া ইনপুট ডিজিট দিয়ে শেষ হয়েছে");
} else {
System.out.println("দেওয়া ইনপুট ডিজিট দিয়ে শেষ হয়নি");
}
}
}
আউটপুট
দেওয়া ইনপুট ডিজিট দিয়ে শেষ হয়েছে
সারসংক্ষেপ:
$— লাইন এন্ড (MULTILINE-এ প্রতিটি লাইন)\\Z— স্ট্রিং এন্ড, ফাইনাল লাইন টার্মিনেটর অনুমোদন\\z— স্ট্রিংয়ের আসলো৫ এন্ড (কোনো লাইন টার্মিনেটর অনুমোদন না)
স্ট্রিক্ট ভ্যালিডেশনের জন্য \\z সেরা।