i have an example of the following string (all this in one string).
6 x 9 + 4 = 58.0
</br> 58.0 markers cost $33.
</br> 33/ 58.0 = 0.5689655172413793
<br>Each marker cost $0.5689655172413793 .
<br> 0.5689655172413793 x 9 = 5.120689655172414
<br>Each eraser cost $5.120689655172414
<br> (5.120689655172414 x 3) + (0.5689655172413793 x 10) = 21.051724137931036
<br>The total cost is $21.051724137931036 .
I want to remove all the other stuff and get only the mathematical expressions..
6 x 9 + 4 = 58.0
33/ 58.0 = 0.5689655172413793
0.5689655172413793 x 9 = 5.120689655172414
(5.120689655172414 x 3) + (0.5689655172413793 x 10) = 21.051724137931036
I have tried the regex pattern to remove all the other stuff but it get splitted indvidually one char by one char.
Matcher matcher = Pattern.compile("(\\d+|[\\+\\-*/=()])").matcher(qalist.get(i).getFullsol());
while(matcher.find())
{
System.out.println(matcher.group(0));
}
Anyone can help? :)
Encountered Problem
Matcher matcher = Pattern.compile("\\(?(\\d+(?:\\.\\d+)?[^=:a-wyz]+)=\\s*(\\d+(?:\\.\\d+)?)").matcher("The expression is (9 * 1) -1 = 8 ");
I will get :
Expression: 9 * 1) -1
Answer: 8
Wonder whats wrong..
Whole expression: (5.120689655172414 x 3) + (0.5689655172413793 x 10) = 21.051724137931036
Expression: 5.120689655172414 x 3) + (0.5689655172413793 x 10)
Answer: 21.051724137931036
<br>tags in the string too?