Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/323.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java中正则表达式的部分匹配_Java_Regex_String_Pattern Matching - Fatal编程技术网

Java中正则表达式的部分匹配

Java中正则表达式的部分匹配,java,regex,string,pattern-matching,Java,Regex,String,Pattern Matching,我如何理解正则表达式是否部分匹配其主题 我试过这个: Pattern.compile("^\\d").matcher("01L").hitEnd() 这是: Pattern.compile("^\\d").matcher("01L").matches() 它们都是false,我想测试字符串是否以数字开头。使用方法: PS:如果您在循环中或多次使用find,最好执行以下操作: Pattern p = Pattern.compile("^\\d"); // outside l

我如何理解正则表达式是否部分匹配其主题

我试过这个:

Pattern.compile("^\\d").matcher("01L").hitEnd()
这是:

Pattern.compile("^\\d").matcher("01L").matches()
它们都是false,我想测试字符串是否以数字开头。

使用方法:

PS:如果您在循环中或多次使用
find
,最好执行以下操作:

Pattern p = Pattern.compile("^\\d"); // outside loop
boolean valid = p.matcher("01L").find(); // repeat calls
您将获得:

  • matches
    尝试根据模式匹配整个输入,因此返回
    false
  • hitEnd
    返回
    true
    如果搜索引擎在该匹配器执行的最后一次匹配操作中命中了输入的结尾,并且由于没有得到
    false
使用方法:

PS:如果您在循环中或多次使用
find
,最好执行以下操作:

Pattern p = Pattern.compile("^\\d"); // outside loop
boolean valid = p.matcher("01L").find(); // repeat calls
您将获得:

  • matches
    尝试根据模式匹配整个输入,因此返回
    false
  • hitEnd
    返回
    true
    如果搜索引擎在该匹配器执行的最后一次匹配操作中命中了输入的结尾,并且由于没有得到
    false