首页 > 编程语言 >无涯教程-Java 正则 - Matcher boolean hitEnd函数

无涯教程-Java 正则 - Matcher boolean hitEnd函数

时间:2023-12-30 22:34:47浏览次数:25  
标签:Java String Matcher 无涯 boolean matcher hitEnd end

是否是最后一人匹配项,如果是则返回true。

boolean hitEnd() - 声明

以下是 java.time.Matcher.hitEnd()方法的声明。

public boolean hitEnd()

boolean hitEnd() - 返回值

如果是最后一个匹配项,则返回为true;否则为false

boolean hitEnd() - 示例

下面的示例显示java.time.Matcher.hitEnd()方法的用法。

package com.learnfk;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class MatcherDemo {
   private static String REGEX = "(a*b)(foo)";
   private static String INPUT = "aabfooaabfooabfoob";
   private static String REPLACE = "-";
   
   public static void main(String[] args) {
      Pattern pattern = Pattern.compile(REGEX);
      
      //get a matcher object
      Matcher matcher = pattern.matcher(INPUT);
      
      while(matcher.find()) {
         //Prints the offset after the last character matched.
         System.out.println("First Capturing Group, (a*b) Match String end(): "+matcher.end());    
      }
      System.out.println("hitEnd(): "+matcher.hitEnd());    
   }
}

让无涯教程编译并运行以上程序,这将产生以下输出-

First Capturing Group, (a*b) Match String end(): 6
First Capturing Group, (a*b) Match String end(): 12
First Capturing Group, (a*b) Match String end(): 17
hitEnd(): true

参考链接

https://www.learnfk.com/javaregex/javaregex-matcher-hitend.html

标签:Java,String,Matcher,无涯,boolean,matcher,hitEnd,end
From: https://blog.51cto.com/u_14033984/9042192

相关文章

  • 无涯教程-Java 正则 - Matcher boolean lookingAt函数
    java.time.Matcher.lookingAt()方法尝试从区域的开头开始将输入序列与模式进行匹配。booleanlookingAt()-声明以下是java.time.Matcher.lookingAt()方法的声明。publicbooleanlookingAt()booleanlookingAt()-返回值当且仅当输入序列的前缀与此匹配器的模式匹配时,......
  • JavaWebDay9
    一:MyBatis基础操作1.删除在接口后的括号里写sql语句,其中mybatis提供了#{}来动态获取id其实是有返回值的,返回值为影响的数据数,比如这边删除了一列则返回值为1,要获取的话就把void变为int注意#{}不可以出现在引号里面 预编译   2.新增有多个参数可以用实体类将......
  • Java 流程控制
    用户交互ScannerScanner可以获取用户的输入内容,类似于Python的input。基本语法importjava.util.Scanner;Scanners=newScanner(System.in);通过Scanner类的next()与nextline()方法获取输入的字符串,在读取前我们一般需要使用hasNext()与hasNextLine()判断是否还......
  • JavaScript改变this指向的三种方法
    JavaScriptcall()方法它可以用来调用所有者对象作为参数的方法。通过 call(),您能够使用属于另一个对象的方法。varperson={fullName:function(){returnthis.firstName+""+this.lastName;}}varperson1={firstName:"Bill",lastN......
  • java自动化前置基础
     java自动化前置基础(01):配置文件解析(properties)java自动化前置基础(02):jdbc数据库操作java自动化前置基础(03):fastjson的使用(处理json字符串、json数组)java自动化前置基础(04):jsonpath的使用java自动化前置基础(05):java操作excel(通过POI)java自动化前置基础(06):HttpClient的使用(get、po......
  • JavaWebDay8
    一:多表查询 1.内连接(查询的是两张表的交集部分)2.外连接写在left或right左边的是左表数据右边的是右表数据,两个可以互相改造3.子查询a.标量子查询b.列子查询c.行子查询把括号里多余的删除,例如上述中entrydate中job是多余的则把job删除,而job中entrydate是多余的......
  • 无涯教程-Java 正则 - Matcher boolean hasTransparentBounds()函数
    java.time.Matcher.hasTransparentBounds()方法查询此匹配器的区域边界。booleanhasTransparentBounds()-声明以下是java.time.Matcher.hasTransparentBounds()方法的声明。publicbooleanhasTransparentBounds()booleanhasTransparentBounds()-返回值如果此匹配器......
  • 无涯教程-Java 正则 - Matcher boolean hasAnchoringBounds()函数
    java.time.Matcher.hasAnchoringBounds()方法查询此匹配器的区域边界定位。booleanhasAnchoringBounds()-声明以下是java.time.Matcher.hasAnchoringBounds()方法的声明。publicbooleanhasAnchoringBounds()booleanhasAnchoringBounds()-返回值如果此匹配器使用锚......
  • 解决Java无效发行版本
    1.问题及原因平时工作学习中我们在使用idea开发中经常会遇到以下问题,java:“无效的目标发行版:11”冲突。如下图:其实出现问题的真正原因是你download别人的代码,但是别人的JDK属于java11或者java9,但是i你的为java8或者更低,所以会出现以下的问题,那应该如何解决呢? 2.解决......
  • 无涯教程-Java 正则 - Matcher int groupCount函数
    java.time.Matcher.groupCount()方法返回此匹配器模式中的捕获组数。intgroupCount()-声明以下是java.time.Matcher.groupCount()方法的声明。publicintgroupCount()intgroupCount()-返回值此匹配器模式中的捕获组数。intgroupCount()-示例下面的示例显示jav......