java - Split words from string into array but not if they are inbetween slashes -
i have code:
string path;  path = main.getinput(); // lets getinput() "hello \wo rld\" args = path.split("\\s+");  (int = 0; < args.length; i++) {      system.out.println(args[i]); } is there way split string words split , put array, if not in between 2 backslashes, "wo rld" 1 word , not two?
you try splitting on spaces followed number of backslashes. raw regex:
\s+(?=(?:[^\\]*\\[^\\]*\\)*[^\\]*$) java escaped regex:
\\s+(?=(?:[^\\\\]*\\\\[^\\\\]*\\\\)*[^\\\\]*$) 
Comments
Post a Comment