Most visited

Recently visited

Added in API level 1

MatchResult

public interface MatchResult

java.util.regex.MatchResult
Known Indirect Subclasses


匹配操作的结果。

此接口包含用于确定针对正则表达式的匹配结果的查询方法。 通过MatchResult可以看到匹配边界,组和边界。

也可以看看:

Summary

Public methods

abstract int end(int group)

返回此匹配期间给定组捕获的子序列的最后一个字符后的偏移量。

abstract int end()

返回匹配的最后一个字符后的偏移量。

abstract String group(int group)

返回上一次匹配操作期间给定组所捕获的输入子序列。

abstract String group()

返回前一次匹配所匹配的输入子序列。

abstract int groupCount()

返回此匹配结果模式中的捕获组数量。

abstract int start()

返回匹配的开始索引。

abstract int start(int group)

返回此匹配期间给定组捕获的子序列的起始索引。

Public methods

end

Added in API level 1
int end (int group)

返回此匹配期间给定组捕获的子序列的最后一个字符后的偏移量。

Capturing groups从左到右索引,从1开始。 零组表示整个模式,所以表达式m。 end(0)相当于m。 end()

Parameters
group int: The index of a capturing group in this matcher's pattern
Returns
int The offset after the last character captured by the group, or -1 if the match was successful but the group itself did not match anything
Throws
IllegalStateException If no match has yet been attempted, or if the previous match operation failed
IndexOutOfBoundsException If there is no capturing group in the pattern with the given index

end

Added in API level 1
int end ()

返回匹配的最后一个字符后的偏移量。

Returns
int
Throws
IllegalStateException If no match has yet been attempted, or if the previous match operation failed

group

Added in API level 1
String group (int group)

返回上一次匹配操作期间给定组所捕获的输入子序列。

对于匹配器m ,输入序列s和组索引g ,表达式m。 group( g )s。 substring( m。 start( g ), m。 end( g ))是等同的。

Capturing groups从左到右索引,从1开始。 组零表示整个模式,因此表达式m.group(0)等同于m.group()

如果匹配成功但指定的组未能匹配输入序列的任何部分,则返回null 请注意,某些组(例如(a*) )与空字符串匹配。 当这个组成功匹配输入中的空字符串时,此方法将返回空字符串。

Parameters
group int: The index of a capturing group in this matcher's pattern
Returns
String The (possibly empty) subsequence captured by the group during the previous match, or null if the group failed to match part of the input
Throws
IllegalStateException If no match has yet been attempted, or if the previous match operation failed
IndexOutOfBoundsException If there is no capturing group in the pattern with the given index

group

Added in API level 1
String group ()

返回前一次匹配所匹配的输入子序列。

对于具有输入序列s的匹配器m ,表达式m。 group()s。 substring(米 start(), m。 end())是等同的。

请注意,某些模式(例如a* )与空字符串匹配。 当模式成功匹配输入中的空字符串时,此方法将返回空字符串。

Returns
String The (possibly empty) subsequence matched by the previous match, in string form
Throws
IllegalStateException If no match has yet been attempted, or if the previous match operation failed

groupCount

Added in API level 1
int groupCount ()

返回此匹配结果模式中的捕获组数量。

零组表示按照惯例的整个模式。 这不包括在这个计数中。

Any non-negative integer smaller than or equal to the value returned by this method is guaranteed to be a valid group index for this matcher.

Returns
int The number of capturing groups in this matcher's pattern

start

Added in API level 1
int start ()

返回匹配的开始索引。

Returns
int The index of the first character matched
Throws
IllegalStateException If no match has yet been attempted, or if the previous match operation failed

start

Added in API level 1
int start (int group)

返回此匹配期间给定组捕获的子序列的起始索引。

Capturing groups从左到右索引,从1开始。 零组表示整个模式,所以表达式m。 start(0)相当于m。 start()

Parameters
group int: The index of a capturing group in this matcher's pattern
Returns
int The index of the first character captured by the group, or -1 if the match was successful but the group itself did not match anything
Throws
IllegalStateException If no match has yet been attempted, or if the previous match operation failed
IndexOutOfBoundsException If there is no capturing group in the pattern with the given index

Hooray!