-2

Currently I have a string where it signifies an expression (i.e., "2+4*8/2") and is there a way to convert this to a regular expression that is NOT a string so it can return 18?

If not, is there a way to detect what kind of operator it is at a given character?

In Java would help.

Thank you.

  • 2
    What do you mean by "a regular expression that is not a string"? Do you want to evaluate the expression? – Salem Feb 12 '18 at 20:08
  • What? Are you actually asking to compile this to a mathematical expression and run it? – Darren Forsythe Feb 12 '18 at 20:08
  • https://stackoverflow.com/questions/3422673/evaluating-a-math-expression-given-in-string-form – GriffeyDog Feb 12 '18 at 20:08
  • Java *itself* does not offer such a method. However, Java has a built-in Javascript engine that offers the usual *eval* method. So as long as the equation stays as simple as this you can use this to parse and evaluate the equation. For details, refer to the linked duplicate. – Zabuzard Feb 12 '18 at 20:14
  • 1
    Please note that you should do a quick research prior to posting a question on SO, thanks (see [ask]). – Zabuzard Feb 12 '18 at 20:16
  • Note that a "regular expression" is a thing that's entirely different to what you're looking for. You might cause some confusion if you try to explain it as such. – Bernhard Barker Feb 12 '18 at 20:28

1 Answers1

0

Possibly what you can do is you can convert this String into a char Array and you can perform your own implementation because conmpiler cant convert your expression into a mathemathical form....

Shivam Pandey
  • 86
  • 2
  • 8