自己一直使用scanner.useDelimiter("\\A")来读去网页,但是一直不知道这个\\A是什么意思。今天才弄明白。
首先摘自 https://stackoverflow.com/questions/12500284/java-regex-explanation#comment16821903_12500284 的一句话:
然后查看源码知道useDelimiter 下面的实现使用的是Pattern,参考文章得知:
\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 usingPattern.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).
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 |
\b | A word boundary |
\B | A non-word boundary |
\A | The beginning of the input |
\G | The end of the previous match |
\Z | The end of the input but for the final terminator, if any |
\z | The end of the input |