This question already has answers here:
Closed 5 years ago.
So i have this code:
Pattern pattern = Pattern.compile("\\d*(\\s\\d+\\.)*\\s*[-\\+\\*/\\$£]");
String input = "4.0 5.0 2.0 / + 7.0 - 11.0 34.0 2.0 / 3.0 / 1.0 * +";
Matcher matcher = pattern.matcher(input);
List<String> output = new ArrayList<>();
while (matcher.find()) {
output.add(matcher.group());
}
When i was working on just parsing integers the regex was of course fine however i now need it to take into account that there can be a . to represent a floating point.
Wondering if someone can help me with adding this in
expected output should be :
4.0 5.0 2.0 /
+
7.0 -
11.0 34.0 2.0 /
3.0 /
1.0 *
+