正则表达式Java

vr信息:

我正在尝试输入之间的内容,我的模式没有做正确的事,请帮忙。

下面是sudocode:

s="Input one Input Two Input Three";
Pattern pat = Pattern.compile("Input(.*?)");
Matcher m = pat.matcher(s);

 if m.matches():

   print m.group(..)

要求的输出:

之一

马克·拜尔斯(Mark Byers):

先行使用Inputfind在循环中使用,而不是matches

Pattern pattern = Pattern.compile("Input(.*?)(?=Input|$)");
Matcher matcher = pattern.matcher(s);
while (matcher.find()) {
   System.out.println(matcher.group(1));
}

看到它在线上工作:ideone

但是最好在这里使用split:

String[] result = s.split("Input");
// You need to ignore the first element in result, because it is empty.

看到它在线上工作:ideone

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章