java - Getting value of string inside some regular expression -
i have code this:
string s1 = "((${adapterkind=vmware, resourcekind=virtualmachine, metric=disk|usage_average}*${this, metric=summary|oversizedvmcount})+${this, metric=summary|poweredoffvmcount})"; //some code want output inside string[] s2 = {${adapterkind=vmware, resourcekind=virtualmachine, metric=disk|usage_average}, ${this, metric=summary|oversizedvmcount}, ${this, metric=summary|poweredoffvmcount}};
basically want values "${...}". how can achieve this?
string s1 = "((${adapterkind=vmware, resourcekind=virtualmachine, metric=disk|usage_average}*${this, metric=summary|oversizedvmcount})+${this, metric=summary|poweredoffvmcount})"; pattern p = pattern.compile("\\$\\{[^}]*\\}"); matcher m = p.matcher(s1); while(m.find()) //here have captured texts, //you can put array/collection system.out.println(m.group());
this output:
${adapterkind=vmware, resourcekind=virtualmachine, metric=disk|usage_average} ${this, metric=summary|oversizedvmcount} ${this, metric=summary|poweredoffvmcount}
Comments
Post a Comment