A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

自己一直使用scanner.useDelimiter("\\A")来读去网页,但是一直不知道这个\\A是什么意思。今天才弄明白。

首先摘自 https://stackoverflow.com/questi ... nt16821903_12500284 的一句话:



\A means "start of string", and \z means "end of string".
You might have seen ^ and $ in this context, but their meaning can vary: If you compile a regex using Pattern.MULTILINE, then they change their meaning to "start of line" and "end of line". The meaning of \A and \z never changes.
There also exists \Z which means "end of string, before any trailing newlines", which is similar to what $ does in multiline mode (where it matches right before the line-ending newline character, if it's there).
然后查看源码知道useDelimiter 下面的实现使用的是Pattern,参考文章得知:

https://docs.oracle.com/javase/7/docs/api/java/util/regex/Pattern.html

Boundary matchers
^The beginning of a line
$The end of a line
\bA word boundary
\BA non-word boundary
\AThe beginning of the input
\GThe end of the previous match
\ZThe end of the input but for the final terminator, if any
\zThe end of the input


1 个回复

倒序浏览
奈斯
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 加入黑马