Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/17.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 scjp测试中的正则表达式测试_Java_Regex - Fatal编程技术网

Java scjp测试中的正则表达式测试

Java scjp测试中的正则表达式测试,java,regex,Java,Regex,我正在尝试解决一个关于regex的scjp测试 这是一个代码 import java.util.regex.*; public class TestRegex { public static void main(String[] args) { Pattern p = Pattern.compile(args[0]); Matcher m = p.matcher(args[1]); boolean b = false; w

我正在尝试解决一个关于regex的scjp测试

这是一个代码

import java.util.regex.*;

public class TestRegex {
    public static void main(String[] args) {
        Pattern p = Pattern.compile(args[0]);
        Matcher m = p.matcher(args[1]);
        boolean b = false;
        while (b = m.find()) {
            System.out.print(m.start() + m.group());
        }
    }
} 

此测试的答案是
01234456
。除了最后的输出,我什么都懂。既然“ab34ef”中的最后一个索引是5,怎么可能打印6


有什么帮助吗

\d*
表示“零或多个数字”,实际上不能匹配任何数字。6与字符串中最后一个字符后的空字符串匹配。

…非常感谢?好的..谢谢..这个空字符串正则表达式是特定的,还是所有字符串都固有的?@我真的不知道你的意思。。这与正则表达式有关
java TestRegex "\d*" ab34ef