【问题标题】:Difference between '\Z' and '\z' in java.util.regex.Pattern [duplicate]java.util.regex.Pattern 中 '\Z' 和 '\z' 之间的区别 [重复]
【发布时间】:2013-10-14 08:45:20
【问题描述】:

JDK6 java.util.regex.Pattern的“边界匹配器”'\z'和'\Z'有什么区别?

背景:我试图将 UTF-8 编码文件的内容读入String。遇到this solution。我发现java.util.scanner.useDelimeter 使用了java.util.regex.Pattern。前面提到的解决方案建议使用 '\Z'。

【问题讨论】:

  • 你能详细解释一下你在read the documentation之后的困惑吗?您的问题读起来就像您看到了令人困惑的匹配器字符并立即在 SO 上发布而无需任何事先研究。
  • 感谢您指出重复的问题。当我使用 '\Z' '\z' 和 java.util.regex.Pattern 搜索时,这个问题并没有出现。
  • @DuncanJones。我的问题是实际差异。事后看来,我似乎应该发布我尝试过的代码。

标签: java regex java-6


【解决方案1】:

根据http://docs.oracle.com/javase/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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-08-12
    • 2012-10-07
    • 2011-06-22
    • 1970-01-01
    • 2021-09-05
    • 2019-07-06
    • 2010-10-09
    相关资源
    最近更新 更多