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+(?=(?:[^\\\\]*\\\\[^\\\\]*\\\\)*[^\\\\]*$) 

ideone demo


Comments

Popular posts from this blog

php - Magento - Deleted Base url key -

javascript - Tooltipster plugin not firing jquery function when button or any click even occur -

java - WrongTypeOfReturnValue exception thrown when unit testing using mockito -