+ 3
Are /A and /Z the same as ^ and $?
2 Antworten
+ 9
^ Matches the beginning of a line.
$ Matches the end of a line.
\A Matches the beginning of the string.
\z Matches the end of the string.
\Z Matches the end of the string unless the string ends with a "\n", in which case it matches just before the "\n".
/^foo$/ matches any of the following, /\Afoo\z/ does not:
whatever1
foo
whatever
---
foo
whatever2
---
whatever1
foo
/^foo$/ and /\Afoo\z/ all match the following:
foo
+ 1
Strictly...no...because line/string are different concepts and also syntax: although we know what you mean the parser will not: / is not \. (Sure it's a rigid answer, but you're contrasting strings with metacharacters and regex cares)