你们中的任何人都可以帮帮我吗?我有一个字符串下载到“结果”,如下所示:
DrawDate,Ball 1,Ball 2,Ball 3,Ball 4,Ball 5,Ball 6,Bonus Ball,Ball Set,Machine27-Feb-2013,2,24,14,23,20,30,22,6,MERLIN23-Feb-2013,31,25,32,2,30,16,36,5,MERLIN20-Feb-2013,36,45,3,6,44,48,47,8,MERLIN16-Feb-2013,7,27,48,46,39,20,49,6,ARTHUR13-Feb-2013,6,49,23,29,14,20,48,8,MERLIN09-Feb-2013,10,8,34,40,27,41,48,7,MERLIN06-Feb-2013,9,18,10,16,27,42,43,6,ARTHUR02-Feb-2013,2,13,14,21,12,30,39,7,ARTHUR30-Jan-2013,10,9,43,48,47,24,5,5,ARTHUR26-Jan-2013,2,6,21,29,47,34,11,5,ARTHUR
23-Jan-2013,10,6,32,24,41,14,29,8,MERLIN19-Jan-2013,35,5,9,13,39,16,11,7,ARTHUR16-Jan-2013,13,38,47,12,35,5,45,3,MERLIN12-Jan-2013,3,11,27,24,12,7,13,8,ARTHUR09-Jan-2013,48,39,24,21,5,25,32,6,MERLIN05-Jan-2013,15,37,10,21,17,47,2,5,ARTHUR02-Jan-2013,37,20,30,21,7,9,42,7,MERLIN29-Dec-2012,40,31,6,37,8,48,36,5,GUINEVERE26-Dec-2012,3,11,49,39,47,17,34,6,LANCELOT22-Dec-2012,34,28,4,44,43,14,13,4,LANCELOT
然后使用下面的正则表达式:
Pattern p = Pattern.compile("(Machine|GUINEVERE|LANCELOT|ARTHUR|MERLIN)(.*?)(GUINEVERE|LANCELOT|ARTHUR|MERLIN)");
Matcher m = p.matcher(result);
while (m.find())
{
matchesList.add(m.group());
}
这就是我的列表视图的结果:
1, Machine27-Feb-2013,2,24,14,23,20,30,22,6,LANCELOT
2, MERLIN20-Feb-2013,36,45,3,6,44,48,47,8,GUINEVER
3, ARTHUR13-Feb-2013,6,49,23,29,14,20,48,8,MERLIN
但是正则表达式错过了每一行:
1, Machine27-Feb-2013,2,24,14,23,20,30,22,6,LANCELOT
2, 23-Feb-2013,31,25,32,2,30,16,36,5,
3, MERLIN20-Feb-2013,36,45,3,6,44,48,47,8,GUINEVER
4, 16-Feb-2013,7,27,48,46,39,20,49,6,
5, ARTHUR13-Feb-2013,6,49,23,29,14,20,48,8,MERLIN
6, 09-Feb-2013,10,8,34,40,27,41,48,7,
这就是我所追求的:
1, 27-Feb-2013,2,24,14,23,20,30,22,6
2, 23-Feb-2013,31,25,32,2,30,16,36,5
3, 20-Feb-2013,36,45,3,6,44,48,47,8
4, 16-Feb-2013,7,27,48,46,39,20,49,6
5, 13-Feb-2013,6,49,23,29,14,20,48,8
6, 09-Feb-2013,10,8,34,40,27,41,48,7
这适用于C# "(?s)(?<=Machine|GUINEVERE|LANCELOT|ARTHUR|MERLIN).*?(GUINEVERE|LANCELOT|ARTHUR|MERLIN)"
但不适用于Java,
从网上试了很多方法都无济于事。试过^和$但不明白如何工作?