Whats the difference between \z and \Z in a regular expression and when and how do I use it?

Posted by Mister M. Bean on Stack Overflow See other posts from Stack Overflow or by Mister M. Bean
Published on 2010-04-25T10:32:38Z Indexed on 2010/04/25 10:33 UTC
Read the original article Hit count: 153

Filed under:
|

From http://java.sun.com/j2se/1.5.0/docs/api/java/util/regex/Pattern.html:

\Z  The end of the input but for the final terminator, if any
\z  The end of the input

But what does it mean in practice? Can you give me an example when I use either the \Z or \z.

In my test I thought that "StackOverflow\n".matches("StackOverflow\\z") will return true and "StackOverflow\n".matches("StackOverflow\\Z") returns false. But actually both return false. Where is the mistake?

© Stack Overflow or respective owner

Related posts about java

Related posts about regex