Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/340.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 (?<;=#!)(\\w+;\.\.\\w+;)&&x2B;不';不匹配!super.composite.key3_Java_Regex_Lookbehind - Fatal编程技术网

Java (?<;=#!)(\\w+;\.\.\\w+;)&&x2B;不';不匹配!super.composite.key3

Java (?<;=#!)(\\w+;\.\.\\w+;)&&x2B;不';不匹配!super.composite.key3,java,regex,lookbehind,Java,Regex,Lookbehind,我写了一个简单的regexp String s = "#!key1 #!compound.key2 #!super.compound.key3"; Matcher matcher = Pattern.compile("(?<=#!)(\\w+\\.*\\w+)+").matcher(s); while (matcher.find()) { System.out.println(matcher.group()); } 我想知道为什么它与super.component匹配,而不是像我预期

我写了一个简单的regexp

String s = "#!key1 #!compound.key2 #!super.compound.key3";
Matcher matcher = Pattern.compile("(?<=#!)(\\w+\\.*\\w+)+").matcher(s);
while (matcher.find()) {
  System.out.println(matcher.group());
}
我想知道为什么它与
super.component
匹配,而不是像我预期的那样与
super.component.key3
匹配

预期 欢迎对regexp进行任何改进。

您需要使用

(?<=#!)\w+(?:\.\w+)*
(?[key1,composite.key2,super.composite.key3]

我想这样写这个正则表达式(?它不匹配,因为您的量化集群在每次迭代开始时查找
\w
,而不是
。因此,当它匹配
super.component
时,它无法匹配下一个
,因为它需要一个
\w
。将您的正则表达式更改为。谢谢,我如何在那里生成正则表达式图?@AndrewTobilko我使用了,但它不支持lookbehinds,我手动编辑了图像。
key1
compound.key2
super.compound.key3
(?<=#!)\w+(?:\.\w+)*
String s = "#!key1 #!compound.key2 #!super.compound.key3";
Matcher matcher = Pattern.compile("(?<=#!)\\w+(?:\\.\\w+)*").matcher(s);
while (matcher.find()) {
    System.out.println(matcher.group());
}
// => [key1, compound.key2, super.compound.key3]