Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Delete the content of a string between a word and special character in java

Tags:

java

string

regex

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!

like image 864
Archit Arora Avatar asked Oct 20 '22 12:10

Archit Arora


2 Answers

You can use the following to match:

('\w+'\s*).*?(?=[,\]])

And replace with $1

regex in java would be ('\\w+'\\s*).*?(?=[,\\]])

See DEMO

like image 162
karthik manchala Avatar answered Oct 27 '22 00:10

karthik manchala


You can use this regex.

('\w+'\s*).*?(?=[,\]])
like image 24
Ranjeet Avatar answered Oct 27 '22 00:10

Ranjeet