开发者

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

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜