- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-02-2020 09:19 PM
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
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-02-2020 10:55 PM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-02-2020 10:32 PM
Did you try using the code?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-02-2020 10:35 PM
Hi Chris, your solution works but i still need to take 3 empty values between "text2" and "text3".
thanks,
ry
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-02-2020 10:51 PM
This might work for you
var str = '"text1","text2","","","","text3","text4,text5"';
var matches = str.match(/".*?"/g); //get any string that starts and ends with double quotes. Search is lazy, so it searches for the shortest possible match each time, which should keep it all separated.
for (var i = 0; i < matches.length; i ++) {
gs.print(matches[i].replace(/"/g,"")); //remove the double quotes from each result.
}
Thanks,
Jeremy
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-02-2020 10:54 PM
Ah, sorry about that. I assumed you wouldn't want the empty quotes. If you need them then change the regex to this:
var regex = /(\"[^\"]*\")/g;
and it will keep the empty quotes in the final array.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-02-2020 10:27 PM
try with below code,
var arr = ["text1","text2","","","","text3","text4,text5"];
for(var i = 0 ; i< arr.length ; i ++){
gs.print(arr[i]);
}