Skip to main content
added 31 characters in body
Source Link
Let'sRefactor
  • 3.4k
  • 4
  • 30
  • 47

The Regular Expression which helps you here is

"(?<=[-+*/()])|(?=[-+*/()])"

and of course, you need to avoid unwanted spaces.

Here we go,

String expr = "(5 + 3) * 12 / 3";
.
. // Your inputs
.
String arr[] = expr.replaceAll("\\s+", "").split("(?<=[-+*/()])|(?=[-+*/()])");
for (String s : arr) {
    System.out.println("Element : " + s);
} 
String expr = "(5 + 3) * 12 / 3";
.
. // Your inputs
.
String arr[] = expr.replaceAll("\\s+", "").split("(?<=[-+*/()])|(?=[-+*/()])");
for (String s : arr) 
{
    System.out.println("Element : " + s);
} 

Please see my expiriment : http://rextester.com/YOEQ4863

Hope it helps.

The Regular Expression which helps you here is

"(?<=[-+*/()])|(?=[-+*/()])"

and of course, you need to avoid unwanted spaces.

Here we go,

String expr = "(5 + 3) * 12 / 3";
.
. // Your inputs
.
String arr[] = expr.replaceAll("\\s+", "").split("(?<=[-+*/()])|(?=[-+*/()])");
for (String s : arr) {
    System.out.println("Element : " + s);
} 

Please see my expiriment : http://rextester.com/YOEQ4863

Hope it helps.

The Regular Expression which helps you here is

"(?<=[-+*/()])|(?=[-+*/()])"

and of course, you need to avoid unwanted spaces.

Here we go,

String expr = "(5 + 3) * 12 / 3";
.
. // Your inputs
.
String arr[] = expr.replaceAll("\\s+", "").split("(?<=[-+*/()])|(?=[-+*/()])");
for (String s : arr) 
{
    System.out.println("Element : " + s);
} 

Please see my expiriment : http://rextester.com/YOEQ4863

Hope it helps.

Source Link
Let'sRefactor
  • 3.4k
  • 4
  • 30
  • 47

The Regular Expression which helps you here is

"(?<=[-+*/()])|(?=[-+*/()])"

and of course, you need to avoid unwanted spaces.

Here we go,

String expr = "(5 + 3) * 12 / 3";
.
. // Your inputs
.
String arr[] = expr.replaceAll("\\s+", "").split("(?<=[-+*/()])|(?=[-+*/()])");
for (String s : arr) {
    System.out.println("Element : " + s);
} 

Please see my expiriment : http://rextester.com/YOEQ4863

Hope it helps.