java.util.regex.Matcher类充当引擎,通过解释模式对字符序列执行匹配操作。
Matcher声明
以下是java.util.regex.Matcher类的声明
public final class Matcher extends Object implements MatchResult
Matcher方法
| Sr.No | Method & 描述 |
|---|---|
| 1 |
Matcher appendReplacement(StringBuffer sb, String replacement) 实现非终结式追加和替换步骤。 |
| 2 |
StringBuffer appendTail(StringBuffer sb) 实现终端附加和替换步骤。 |
| 3 |
int end() 返回匹配的最后一个字符之后的偏移量。 |
| 4 |
int end(int group) 返回在上一个匹配操作期间由给定组捕获的子序列的最后一个字符之后的偏移量。 |
| 5 |
boolean find() 尝试查找与模式匹配的输入序列的下一个子序列。 |
| 6 |
boolean find(int start) 重置此匹配器,然后尝试查找与模式匹配的输入序列的下一个子序列,从指定的索引处开始。 |
| 7 |
String group() 返回给定组在上一次匹配操作期间捕获的输入子序列。 |
| 8 |
String group(String name) 返回给定命名捕获组在上一个匹配操作期间捕获的输入子序列。 |
| 9 |
int groupCount() 返回此匹配器模式中的捕获组的数量。 |
| 10 |
boolean hasAnchoringBounds() 查询此匹配器的区域边界的锚定。 |
| 11 |
boolean hasTransparentBounds() 查询此匹配器的区域边界的透明度。 |
| 12 |
boolean hitEnd() 如果搜索引擎在此匹配器执行的最后一次匹配操作中命中输入末尾,则返回true。 |
| 13 |
boolean lookingAt() 尝试将输入序列与模式进行匹配,从区域的开头开始。 |
| 14 |
boolean matches() 尝试将整个区域与模式进行匹配。 |
| 15 |
Pattern pattern() 返回此匹配器解释的模式。 |
| 16 |
static String quoteReplacement(String s) 返回指定字符串的文字替换字符串。 |
| 17 |
Matcher region(int start, int end) 设置此匹配器区域的限制。 |
| 18 |
int regionEnd() 报告此匹配器区域的结束索引(排除)。 |
| 19 |
int regionStart() 报告此匹配器区域的起始索引。 |
| 20 |
String replaceAll(String replacement) 用给定的替换字符串替换与模式匹配的输入序列的每个子序列。 |
| 21 |
String replaceFirst(String replacement) 用给定的替换字符串替换与模式匹配的输入序列的第一个子序列。 |
| 22 |
boolean requireEnd() 如果更多的输入可以将正匹配更改为负匹配,则返回TRUE。 |
| 23 |
Matcher reset() 重置此匹配器。 |
| 24 |
Matcher reset(CharSequence input) 使用新的输入序列重置此匹配器。 |
| 25 |
int start() 返回上一个匹配项的开始索引。 |
| 26 |
int start(int group) 返回给定组在上一次匹配操作期间捕获的子序列的开始索引。 |
| 27 |
MatchResult toMatchResult() 将此匹配器的匹配状态作为MatchResult返回。 |
| 28 |
String toString() 返回此匹配器的字符串表示形式。 |
| 29 |
Matcher useAnchoringBounds(boolean b) 设置此匹配器的区域边界的锚定。 |
| 30 |
Matcher usePattern(Pattern newPattern) 更改此Matcher用于查找匹配项的模式。 |
| 31 |
Matcher useTransparentBounds(boolean b) 设置此匹配器的区域边界的透明度。 |