0

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 !

jaywalker
  • 1,116
  • 4
  • 26
  • 44
  • In your example: why should it split after `fox`? The whitespace after `fox` is inside ""! – piet.t Feb 19 '14 at 14:31
  • 1
    It is indeed a duplication. I was about to propose a code that would have look very much like aioobe's answer there: http://stackoverflow.com/questions/7804335/split-string-on-spaces-except-if-between-quotes-i-e-treat-hello-world-as. – James Feb 19 '14 at 14:32

0 Answers0