Here's how:
String str = "Location \"Welcome to india\" Bangalore " + "Channai \"IT city\" Mysore"; List<String> list = new ArrayList<String>(); Matcher m = Pattern.compile("([^\"]\\S*|\".+?\")\\s*").matcher(str); while (m.find()) list.add(m.group(1));
Output:
[Location, "Welcome to india", Bangalore, Channai, "IT city", Mysore]
The regular expression just says
[^"] is a token starting with something other than "\S* - followed by zero or more non-spatial characters- ... or...
".+?" - a " is a character followed by everything, to another. "
aioobe Oct 18 '11 at 8:35 2011-10-18 08:35
source share