- 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 09:46 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-02-2020 09:59 PM
May be try regex with the .match method as match will automatically place everything in an array. Then use .map method to strip out the quotes:
var regex = /(\"\w[^\"]*\")/g;
var str = '"text1","text2","","","","text3","text4,text5"';
var finalResults = str.match(regex).map(function makeFinalArr(item){
return item.replace(/\"/g, "");
});
finalResults; // ["text1", "text2", "text3", "text4,text5"]
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-02-2020 10:08 PM
Hi Chris, thank you for the prompt reply. could you please consider the string is not having between 'single quotes'. is that regex works for the below str format?
var str = "text1","text2","text3,text4";
final results;//["text1", "text2", "text3,text4"];
thanks,
ry
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-02-2020 10:26 PM
I'm not pulling from a file so in order to mimic how your data is coming in, the whole thing needs to wrapped in between quotes. Otherwise the small example isn't going to work.