Matcher.lookingAt()和find()之间有什么区别? [英] What's the difference between Matcher.lookingAt() and find()?
问题描述
我正在看Java正则表达式教程,标题几乎解释了自己。看起来像Matcher.lookingAt()试图匹配整个String。这是真的吗?
I am looking at Java regex tutorial, the title pretty much explains itself. It looks like Matcher.lookingAt() is trying to match the entire String. Is that true?
推荐答案
Matcher.lookingAt的文档清楚地解释了区域 lookingAt
尝试匹配:
The documentation for Matcher.lookingAt clearly explains the region lookingAt
tries to match:
与
匹配
方法一样,此方法始终从该地区的开端;与该方法不同,它不需要匹配整个区域。
Like the
matches
method, this method always starts at the beginning of the region; unlike that method, it does not require that the entire region be matched.
所以不, lookingAt
不需要匹配整个字符串。然后 lookingAt
和找到
之间有什么区别?来自 Matcher Javadoc概述:
So no, lookingAt
does not require matching the whole string. Then what's the difference between lookingAt
and find
? From the Matcher Javadoc overview:
匹配
方法尝试匹配整个输入
lookingAt
方法尝试将输入序列(从头开始)与模式匹配。
find
方法扫描输入序列,查找与模式匹配的下一个子序列。
- The
matches
method attempts to match the entire input sequence against the pattern.- The
lookingAt
method attempts to match the input sequence, starting at the beginning, against the pattern.- The
find
method scans the input sequence looking for the next subsequence that matches the pattern.
lookingAt
总是从头开始,但 find
将扫描起始位置。
lookingAt
always starts at the beginning, but find
will scan for a starting position.
以另一种方式查看,匹配
有一个固定的开始和结束, lookingAt
有一个固定的开始但变量结束,而找到
有一个变量的开始和结束。
Viewed another way, matches
has a fixed start and end, lookingAt
has a fixed start but a variable end, and find
has a variable start and end.
这篇关于Matcher.lookingAt()和find()之间有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!