lundi 22 décembre 2014

Pattern not providing expected output

I have the following code:



Pattern pattern = Pattern.compile("\\d*\\s*[-\\+\\*/\\$£]");

String input = "3 3 * 4 + 2 /";
Matcher matcher = pattern.matcher(input);
List<String> output = new ArrayList<>();
while (matcher.find()) {
output.add(matcher.group());
}


for(String s : output){
System.out.println(s);
}


I would very much like the output in my list to be the following:



3 3 *
4 +
2 /


Alas my actual output is:



3 *
4 +
2 /


I am sure there is a regex wizard out there who can show me the issue :)


Aucun commentaire:

Enregistrer un commentaire