Hi,
I'm not a regex expert, and I can't seem to find the solution for this (need to work on my searching skills and regex ).
How can I split the input string entered into string array?
i.e.
From:
I got the following array:Code:dog cat "elephant giraffe" hippo
But I need this:Code:[0] = dog [1] = cat [2] = "elepant [3] = giraffe" [4] = hippo
Or maybe some other alternatives to do the splitting?Code:[0] = dog [1] = cat [2] = elepant giraffe [3] = hippo
My current code:
Thanks in advance.Code:InputStreamReader isr = new InputStreamReader(System.in); BufferedReader br = new BufferedReader(isr); String input= br.readLine().trim(); String[] tokens = input.split("\\s+)"; // regex will not handle spaces enclosed by quotes.




Reply With Quote