正则表达式 - 边界字符(^ 和 $)与转义字符(\A 和\Z)

标签 regex pcre

两者有什么区别

\A  Match at only beginning of 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)

最佳答案

来自 perl 文档(我在标准正则表达式语法中看不到它们):

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.

如果这仅与 Perl(或使用 PCRE、Perl 兼容正则表达式的语言或库)相关,则您应该添加 perl 标记。

关于正则表达式 - 边界字符(^ 和 $)与转义字符(\A 和\Z),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7483549/

相关文章:

python - C++ 将 Python 正则表达式转置为 PCRE

regex - 捕获不属于链接的特定单词的所有出现

r - 将txt文件转换为dataframe

regex - 匹配奇数个转义符

r - 仅在顶层拆分带有嵌套括号的字符串,其中 "level"由括号确定

正则表达式格式 "YYYY/NNNN"或 "YYYY/NNNN/Country code"

php - PHP pcre正则表达式中的命名组

Java/Grails - PrettyTime NLP 可以拆分非日期部分吗?

javascript - 如何使用 javascript/jquery 从 url 中提取文件名?

javascript - 正则表达式在 IE 中返回值,在 Firefox 和 Safari/Chrome 中返回 'undefined'