How to get a string between quotes?

sry
Giga Guru

Hi, i have below string as an example and i need to read the text between quotes. could anyone tell me how to do that in javascript?

this is like csv format string but we do not want to split between COMMA and put it in array because some texts between quotes having COMMAS

"text1","text2","","","","text3","text4,text5"

 

thanks,

ry

1 ACCEPTED SOLUTION

Hemant Goldar
Mega Sage
Mega Sage

Hi sry,

Use this code its working tried in Background Script.

var regex =/"(.*?)"/g

var str = '"text1","text2","","","","text3","text4","text5"';

var finalResults = str.match(regex).map(function makeFinalArr(item){
      return gs.print(item.replace(/\"/g, ""));
});

//finalResults; // ["text1", "text2","","", "text3", "text4,text5"]

hope this helps!
Please mark the reply as Helpful/Correct, if applicable.

Regards,
Hemant

View solution in original post

20 REPLIES 20

Megha Padale
Giga Guru

Hi sry,

I found a blog related to your issue. Please refer this link, it might help you:

https://stackoverflow.com/questions/18893390/splitting-on-comma-outside-quotes

If my answer helped you, please mark answer as helpful and correct.

Thanks and regards,

Megha.