我尝试使用正则表达式解析字符串以获取其中的参数。例如:
谢谢!
字符串:"TestStringpart1 with second test part2" 结果应该是:String[] {"part1", "part2"} 正则表达式:"TestString(.*?) with second test (.*?)"我的测试代码如下:
String regexp = "TestString(.*?) with second test (.*?)"; String res = "TestStringpart1 with second test part2";但它只输出了 "part1",有谁能给我指点一下吗?
Pattern pattern = Pattern.compile(regexp); Matcher matcher = pattern.matcher(res); int i = 0; while(matcher.find()) { i++; System.out.println(matcher.group(i)); }
谢谢!