java - Extract string between characters -


i'd extract 2 arguments given string using regex. example:

c:\users "c:\program files"

c:\mytext.txt mytext2.txt

output c:\users , c:\program files

c:\mytext.txt , mytext2.txt

if string between " " can contain white spaces, otherwise has without them. far managed extract arguments between " ", can't figure out how extract them when 1 argument has " " , other 1 doesn't (like in example above).

pattern p = pattern.compile("\"(.*?)\"");     matcher m = p.matcher(string);     while(m.find()){         system.out.println(m.group(1));     } 

you can use regex matching:

pattern p = pattern.compile("\"[^\"]*\"|\\s+"); 

regex demo


Comments

Popular posts from this blog

ruby - Trying to change last to "x"s to 23 -

jquery - Clone last and append item to closest class -

css - Can I use the :after pseudo-element on an input field? -