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

Capture and play voice with Asterisk ARI -

c++ - Can not find the "fiostream.h" file -

visual studio - Installing Packages through Nuget - "Central Directory corrupt" -