Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/328.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

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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/perl/10.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正则表达式find方法为匹配的罗马数字返回false_Java_Regex_Pattern Matching - Fatal编程技术网

Java正则表达式find方法为匹配的罗马数字返回false

Java正则表达式find方法为匹配的罗马数字返回false,java,regex,pattern-matching,Java,Regex,Pattern Matching,我试图在java中创建一个正则表达式模式来匹配具有特定属性的列表文本。例如: 列表可以匹配(i)或i)。 我使用我对正则表达式的理解得出了一个模式,并在一个在线工具中测试了该版本,它返回了正确的结果。然而,当我在java中实现它时,模式匹配器为find方法返回false 这是psudo代码:' String text = "(i) hello"; String romanNumeralsRegex = "^(\\(|\\[)?((v|x)?i[xv]|(xv|v|x)?i+|(xv|v|x))(

我试图在java中创建一个正则表达式模式来匹配具有特定属性的列表文本。例如:

列表可以匹配
(i)
i)
。 我使用我对正则表达式的理解得出了一个模式,并在一个在线工具中测试了该版本,它返回了正确的结果。然而,当我在java中实现它时,模式匹配器为find方法返回false

这是psudo代码:'

String text = "(i) hello";
String romanNumeralsRegex = "^(\\(|\\[)?((v|x)?i[xv]|(xv|v|x)?i+|(xv|v|x))((\\)|\\]|\\.))";
Pattern pattern = Pattern.compile(romanNumeralsRegex );
Matcher matcher = pattern.matcher(text);
System.out.println(matcher.find());
find()方法返回false。根据我的理解,匹配者应将
组(0)
返回为
(i)
。我不知道我哪里出错了。请求社区的帮助


提前谢谢。

我觉得一切都很正常,除了在您呼叫
Matcher#find后需要呼叫
Matcher#group

if (matcher.find()) {
    System.out.println(matcher.group(0));
}
输出:

(i)

matcher.find()的输出为me@RAZ_Muh_Taz这很奇怪,因为它为我返回false。正如我所说,matcher.find()返回false。它为我返回
true
(i)