What is the difference between ^ and \ A, $ and \ Z in regex?

advertisements

In regular expressions:

  • What is the difference between ^ and \A?
  • What is the difference between $ and \Z?

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.