What is the difference between the JDK6 java.util.regex.Pattern's "Boundary matchers" '\z' and '\Z'?
Background: I was trying to read a UTF-8 encoded file's contents into a String.
home / developersection / forums / can anybody elaborate the difference between “char” and “string” at java
What is the difference between the JDK6 java.util.regex.Pattern's "Boundary matchers" '\z' and '\Z'?
Background: I was trying to read a UTF-8 encoded file's contents into a String.
Kate Smith
14-Oct-2013The difference is anchor \Z matches the empty string just before the newline, while \z matches empty string after the newline.
A very simple example to understand this is:
System.out.println("abc\n".matches("abc\\Z\\n")); // trueSystem.out.println("abc\n".matches("abc\\z\\n")); // false
System.out.println("abc\n".matches("abc\\n\\z")); // true