 
  Data Structure Data Structure
 Networking Networking
 RDBMS RDBMS
 Operating System Operating System
 Java Java
 MS Excel MS Excel
 iOS iOS
 HTML HTML
 CSS CSS
 Android Android
 Python Python
 C Programming C Programming
 C++ C++
 C# C#
 MongoDB MongoDB
 MySQL MySQL
 Javascript Javascript
 PHP PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Regular Expression "z" construct in Java
The subexpression/metacharacter “\z” matches the end of a string.
Example1
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);    } }  Output
Number of matches: 1
Example2
The following Java program verifies whether the given input text ends with a digit.
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");       }    } }  Output
Given input ends with a digit
Advertisements
 