सबएक्सप्रेशन/मेटाकैरेक्टर “\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("मिलान की संख्या: " + 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 \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("दिया गया इनपुट अंक से समाप्त नहीं होता");
}
}
}
आउटपुट
दिया गया इनपुट अंक से समाप्त होता है