I am working on a problem which requires me to tokenize a string on the basis of white spaces except those which occur inside quotation marks. For example for the string :
printf ( " the quick brown fox " ) ;
The tokens generated should be:
printf, (, ", the quick brown fox , ", ), ;
So far I came up with the following code but it does not seem to do what I intend it to.
String m = "printf ( " the quick brown fox " ) ;"
String [] tokens = m.split("([^\"])(\\w)*(\\s)(\\w)*([^\"])");
Any help would be really appreciated !