Reputation:
I have text in csv format like below.
hi="hello",how="are",,,you="",thank="you"
Please help me to get a regex to extract the above text
hello,are,,,,you
Basically I want to take only values in the above key value pairs and keep the commas as they are (technically to frame a perfect csv)
Note: I am actually looking for a pure regex, not with java functions..please.
Thank you
Upvotes: 1
Views: 54
Reputation: 54148
So starting from your sentence :
String str = "hi=\"hello\",how=\"are\",,,you=\"\",thank=\"you\"";
You can remove all occurences of word="
and of "
:
str = str.replaceAll("(\\w*=\"|\")", ""); //remove word=" OR "
Another way, this will catch the group key="value"
and replace it by value
:
str = str.replaceAll("\\w+=\"(.*?)\"", "$1"); // $1 is the value catch in ()
Upvotes: 1