regex - Extract substring containing multiple double quote marks JAVA -


i want extract values between double quote marks in java

sample string:

i sample string. "name":"alfred","age":"95","boss":"batman" end of sample 

the end result should array of: [name,alfred,age,95,boss,batman]

*actual string contain unknown number of values between ""

declare array , store match results that. ([^\"]*) captures character not of " 0 or more times. () called capturing group used capture characters matched pattern present inside group. later refer captured characters through back-referencing.

string s = "i sample string. \"name\":\"alfred\",\"age\":\"95\",\"boss\":\"batman\" end of sample"; pattern regex = pattern.compile("\"([^\"]*)\""); arraylist<string> allmatches = new arraylist<string>(); matcher matcher = regex.matcher(s); while(matcher.find()){         allmatches.add(matcher.group(1));  } system.out.println(allmatches); 

output:

[name, alfred, age, 95, boss, batman] 

Comments

Popular posts from this blog

ruby on rails - RuntimeError: Circular dependency detected while autoloading constant - ActiveAdmin.register Role -

c++ - OpenMP unpredictable overhead -

javascript - Wordpress slider, not displayed 100% width -