正则表达式中^和\ A,$和\ Z有什么区别?

Roh*_*han 15 regex

在正则表达式中:

  • ^和之间有什么区别\A
  • $和之间有什么区别\Z

Ign*_*ams 11

In single-line mode, $ matches either the end of the string, or just before the newline at the end of the string. In multiline mode $ matches before each newline in the string. \Z always matches only the end of the string regardless of the line mode. Same with ^ versus \A.

  • 抱歉,但这不太对.如果最后一个字符是`\n`,`\ Z`匹配字符串的结尾**或**字符串结尾之前的一个.对于绝对的,非哦,只是在案例版本,你想要`\ z`(小zed不是BIG ZED),只有在没有剩余的字符时才能保证匹配.在一些正则表达式语言中,BTW,作为换行符可能是灵活的; 如果你很幸运,它将匹配`(?:(?>\r \n)|\v)`用于任何换行序列,其中`\ v`是Unicode`\p {Vertical_Space}`属性. (2认同)
  • 还有一个对 tchrist 评论的说明:在 Python 中的 `re` 中,`\Z` 等于 Perl/.NET/Java/PCRE 中的 `\z`。 (2认同)

Eug*_*ash 7

perldoc perlre.

\ A和\ Z就像"^"和"$",除了它们在使用/ m修饰符时不会多次匹配,而"^"和"$"将在每个内部行边界匹配.要匹配字符串的实际结尾而不忽略可选的尾随换行符,请使用\ z.