开发者

regex - boundary characters (^ and $) versus escaped characters (\A and \Z)

开发者 https://www.devze.com 2023-04-05 22:18 出处:网络
What are the differences between, \\AMatch at only beginning 开发者_StackOverflowof string \\ZMatch at only end of string (or before newline at the end)

What are the differences between,

\A  Match at only beginning 开发者_StackOverflowof string
\Z  Match at only end of string (or before newline at the end)

^   Match the beginning of the line
$   Match the end of the line (or before newline at the end)


From the perl documentation (I can't see them in the standard regex syntax):

The "\A" and "\Z" are just like "^" and "$", except that they won't match multiple times when the "/m" modifier is used, while "^" and "$" will match at every internal line boundary.

You should be adding a perl tag if this is related just to Perl (or those languages or libraries using PCRE, Perl-Compatible Regular Expressions).


\A always matches the start of a string, and never matches after a line break, while many dialects have the possibility to make ^ match the beginning of a line as well.

http://www.regular-expressions.info/reference.html (look for 'Anchors').

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号