正则表达式:^ 和 \A 之间的区别 [英] Regular Expressions: difference between ^ and \A

查看:52
本文介绍了正则表达式:^ 和 \A 之间的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

^\A 之间的唯一区别是 \A 在换行后永远无法匹配吗?(即使在多行模式下)

Is the only difference between ^ and \A the fact that \A can never match after a line break? (even in multi-line mode)

The PCRE man page says:
^      assert start of string (or line, in multiline mode)
...
\A     matches at the start of the subject

谢谢!

推荐答案

是的.\A 将匹配您的值的最开头.^ 将匹配值的开头,但在多行模式(//m)下也会在换行符之后立即匹配.

Yes. \A will match at the very beginning of your value. ^ will match the beginning of the value, but will also match immediately after newlines in multiline mode (//m).

\Z 类似,但以值结尾.但是,它会在值末尾的换行符之前匹配.如果您不想要这种行为,请使用 \z,它在值的末尾匹配 only.

The \Z is similar, but with the end of the value. However, it will also match before a newline at the end of the value. If you don't want this behaviour, use \z, which matches only at the end of the value.

有用的参考:perlre 手册页

这篇关于正则表达式:^ 和 \A 之间的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆