“正则表达式 Matcher 类”的版本间的差异

来自姬鸿昌的知识库
跳到导航 跳到搜索
第6行: 第6行:
  
 
需要调用 Pattern 对象的 matcher 方法来获得1个 Matcher 对象。
 
需要调用 Pattern 对象的 matcher 方法来获得1个 Matcher 对象。
 +
 +
=== 方法一览 ===
 +
{| class="wikitable"
 +
!方法
 +
!说明
 +
|-
 +
|public int start()
 +
|返回以前匹配的初始索引
 +
|-
 +
|public int start(int group)
 +
|返回在以前的匹配操作期间,由给定组所捕获的子序列的初始索引
 +
|-
 +
|public int end()
 +
|返回最后匹配字符之后的偏移量
 +
|-
 +
|public int end(int group)
 +
|返回在以前的匹配操作期间,由给定组所捕获子序列的最后字符之后的偏移量
 +
|-
 +
|public boolean lookingAt()
 +
|尝试将从区域开头开始的输入序列与该模式匹配
 +
|-
 +
|public boolean find()
 +
|尝试查找与该模式匹配的输入序列的下一个子序列
 +
|-
 +
|public boolean find(int start)
 +
|重置此匹配器,然后尝试查找匹配该模式、从指定索引开始的输入序列的下一个子序列
 +
|-
 +
|public boolean matches()
 +
|尝试将整个区域与模式匹配
 +
|}

2022年11月19日 (六) 11:07的版本

https://www.bilibili.com/video/BV1Eq4y1E79W/?p=19

Matcher 对象是对输入字符串进行解释和匹配的引擎。

与 Pattern 类一样,Matcher 也没有公共构造方法。

需要调用 Pattern 对象的 matcher 方法来获得1个 Matcher 对象。

方法一览

方法 说明
public int start() 返回以前匹配的初始索引
public int start(int group) 返回在以前的匹配操作期间,由给定组所捕获的子序列的初始索引
public int end() 返回最后匹配字符之后的偏移量
public int end(int group) 返回在以前的匹配操作期间,由给定组所捕获子序列的最后字符之后的偏移量
public boolean lookingAt() 尝试将从区域开头开始的输入序列与该模式匹配
public boolean find() 尝试查找与该模式匹配的输入序列的下一个子序列
public boolean find(int start) 重置此匹配器,然后尝试查找匹配该模式、从指定索引开始的输入序列的下一个子序列
public boolean matches() 尝试将整个区域与模式匹配