Reputation: 2636
I have a string like this -
['name' {d763e18f-1719-480b-bcd6-8fea7bad894e} Parameter, 'class' {8471633e-4a54-4c86-bd2b-56d58baf2fbb} Parameter, 'id' {23471633e-4a54-4c86-bd2b-56d58baf2fbb} Parameter]
And I want the following result -
['name' , 'class' , 'id']
All the content between the word in quotes ''
and ,
should be deleted.
How do I achieve this? Thanks!
Upvotes: 5
Views: 127
Reputation: 136162
try this
Matcher m = Pattern.compile("'.+?'").matcher(str);
StringBuilder sb = new StringBuilder();
while(m.find()) {
if (sb.length() > 0) {
sb.append(',');
}
sb.append(m.group());
}
String res = sb.toString();
Upvotes: 0
Reputation: 13650
You can use the following to match:
('\w+'\s*).*?(?=[,\]])
And replace with $1
regex in java would be ('\\w+'\\s*).*?(?=[,\\]])
See DEMO
Upvotes: 2