Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/367.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 - Fatal编程技术网

Java 无法匹配字符串";“帮助”;“在字符串中”;[帮助]”;使用正则表达式

Java 无法匹配字符串";“帮助”;“在字符串中”;[帮助]”;使用正则表达式,java,regex,Java,Regex,我无法使此项正确匹配。它只打印“[help]”,但我希望它与括号内的字符匹配 想要: 代码: Pattern p = Pattern.compile("\\[(\\w+)\\]"); Matcher m = p.matcher("[help]"); m.find(); for (int i=0;i<m.groupCount(); i++) { System.out.println(m.group(i

我无法使此项正确匹配。它只打印“[help]”,但我希望它与括号内的字符匹配

想要:

代码:

        Pattern p = Pattern.compile("\\[(\\w+)\\]");
        Matcher m = p.matcher("[help]");
        m.find();


        for (int i=0;i<m.groupCount(); i++) {
            System.out.println(m.group(i));
        }
Pattern p=Pattern.compile(\\[(\\w+\\\]);
Matcher m=p.Matcher(“[help]”);
m、 查找();

对于(int i=0;i你需要检查
你需要检查
你可能需要更多的反斜杠。Java REs:)通常是这样的(在我提交到ideone之前就被击败了),你可能需要更多的反斜杠。Java REs:)通常是这样的(我还没完成向ideone提交的任务就被打败了)
        Pattern p = Pattern.compile("\\[(\\w+)\\]");
        Matcher m = p.matcher("[help]");
        m.find();


        for (int i=0;i<m.groupCount(); i++) {
            System.out.println(m.group(i));
        }
for (int i = 0; i <= m.groupCount(); i++) {