- 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:31 PM
Hi Harsha, thank you.
It is not an array. it is only a string and i still need to split it or regex it and put final results in array.
var str = "text1","text2","","","","text3,text4";
thanks,
ry

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-02-2020 10:33 PM
you have to push into an array, it would be easy after that.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-02-2020 10:42 PM
Hi Harsha, sorry i do not understand but my question itself is about how to push the string between quotes into array(including empty values).
thanks,
ry

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-02-2020 10:45 PM
quick question , how are you getting the value ? and where are you using the script ?
assuming you get it from some column , you you just first store as string and then push them into an array using push()
once you will push then into an array you can read empty value as well,
- 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