C#Regex中是否有等效的java.util.regex.Matcher.hitEnd()
?C#相当于java Matcher.hitEnd()
Javadoc文档boolean hitEnd()
:
返回true,如果输入的结尾是由搜索引擎由此匹配执行的最后匹配操作的打击。当此方法返回true时,则可能有更多输入会改变上次搜索的结果。
@return true如果输入的结尾在最后一场比赛中被击中,否则为false
C#Regex中是否有等效的java.util.regex.Matcher.hitEnd()
?C#相当于java Matcher.hitEnd()
Javadoc文档boolean hitEnd()
:
返回true,如果输入的结尾是由搜索引擎由此匹配执行的最后匹配操作的打击。当此方法返回true时,则可能有更多输入会改变上次搜索的结果。
@return true如果输入的结尾在最后一场比赛中被击中,否则为false
不可以,但也不是很难建立它自己。如果使用Regex.Matches(…)
返回MatchCollection
最后成功的匹配,需要(用少量Enumerable
帮助)
bool hitEnd = match.Success && input.Length == (match.Index + match.Length)
和可以很容易地扩展方法:
如果使用Regex.Match(…)
(即匹配表达式一次),然后:
static bool HitEnd(this MatchCollection matches, string input) {
if (matches.Count == 0) {
return false; // No matches at all
}
var lastMatch = matches.Cast<Match>().Last();
return input.Length == (lastMatch.Index + lastMatch.Length)
}
难道这不等于'stuff_here $'? –
你对这种方法的理解是什么 –
[同](http://stackoverflow.com/questions/2526756/can-java-util-regex-pattern-do-partial-matches),但在C#中 – Michael