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!
You can use the following to match:
('\w+'\s*).*?(?=[,\]])
And replace with $1
regex in java would be ('\\\\w+'\\\\s*).*?(?=[,\\\\]])
See DEMO
你可以使用这个正则表达式。
('\w+'\s*).*?(?=[,\]])
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();
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.