Split String using regex in java -


i'm new regex, i'm trying split string conditions don't know how it.

here sample/condition

string str = sum1=x+(5+a)  array[0] = sum1 array[1] = = array[2] = x array[3] = + array[4] = ( array[5] = 5 array[6] = + array[7] = array[8] = ) 

i want string split +,-,*,\,(,),=
possible?

if really need use regex should use look-around mechanism since don't want split at characters, before or after them.

string str = "sum1=x+(5+a)"; string[] array=str.replaceall("\\s+","")//remove spaces                   .split("(?<=[+\\-*\\\\()=/])|(?=[+\\-*\\\\()=/])"); (int i=0; i<array.length; i++)     system.out.println("array["+i+"] = "+array[i]); 

output:

array[0] = sum1 array[1] = = array[2] = x array[3] = + array[4] = ( array[5] = 5 array[6] = + array[7] = array[8] = ) 

Comments

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

c++ - qgraphicsview horizontal scrolling always has a vertical delta -