/* package whatever; // don't place package name! */ import java.util.*;import java.lang.*;import java.io.*; /* Name of the class has to be "Main" only if the class is public. */class Ideone{ public static void main (String[] args) throws java.lang.Exception { String input = "7+4-(18/3)/2a^222+1ab"; String temp[] = input.split("(?<=[\\(\\)\\+\\-*\\/\\^A-Za-z])|(?=[\\(\\)\\+\\-*\\/\\^A-Za-z])"); System.out.println(Arrays.toString(temp)); }}
Standard input is empty
[7, +, 4, -, (, 18, /, 3, ), /, 2, a, ^, 222, +, 1, a, b]
The brand new service which powers Ideone!
Widget for compiling and running the source code in a web browser!