Related
I have a Google Sheet that contains data I need to manipulate. It is essentially a list of assignments by student. The original columns are:
Name, ID, Assignment 1, Assignment 2, Assignment 3, Assignment 4, Date, Overall Grade
Using existing code, I am concatenating the Assignments into a single field and creating an array with these columns:
ID, Name, Assignments, Date, Overall Grade
The resulting array looks like this:
[ [ '1234',
'Santa Claus',
'US History Chapter 1.1, , , ',
Fri Nov 18 2022 00:00:00 GMT-0800 (Pacific Standard Time),
'B+' ],
[ '1234',
'Santa Claus',
'US History Chapter 2.1, US History Chapter 1.1, , ',
Thu Nov 17 2022 00:00:00 GMT-0800 (Pacific Standard Time),
'B' ],
[ '12222',
'Mary Poppins',
'US History Chapter 8, , , ',
Fri Nov 18 2022 00:00:00 GMT-0800 (Pacific Standard Time),
'A' ]]
On a separate sheet I have a list of dates. What I want is to have a line for every single student and date combination and the assignment data if it exists. E.g. If the dates are Nov 17, Nov 18, and Nov19 and there are 2 students with data in the list, there would be 6 total entries sorted by student then by date. For the Assignments column, there would only be data if there was an assignment entered for that date and that student. Otherwise it would be blank. For example:
ID
Name
Assignments
Date
Grade
1234
Santa Claus
Chapter 2.1, US History Chapter 1.1
Nov17
B
1234
Santa Claus
US History Chapter 1.1
Nov18
B+
1234
Santa Claus
Nov19
12222
Mary Poppins
Nov17
12222
Mary Poppins
US History Chapter 8
Nov 18
A
12222
Mary Poppins
Nov19
What I think is needed is something like this:
Get unique list of all student IDs from the array
Get list of dates from the sheet
Use a nested loop to go through each date and each student to create the lines. If there is a match for the assignment data, add it, if not, leave that blank.
I'm just not sure how to manipulate the array to do something like that. How would I approach this?
Although, unfortunately, I cannot know your actual array, from your showing sample array and a sample table, how about the following sample script?
Sample script:
const array = [,,,]; // Please set your array.
const res = Object.entries(array.reduce((o, e) => (o[e[0]] = o[e[0]] ? [...o[e[0]], e] : [e], o), {}))
.sort(([a], [b]) => Number(a) > Number(b) ? 1 : -1)
.flatMap(([, v]) => v.sort((a, b) => a[3].getTime() > b[3].getTime() ? 1 : -1));
console.log(res)
In this sample script, first, an object is created by checking the column "A". And, sort the array by the column "A". And, for each element, sort the column "D". And, all values are merged as a 2-dimensional array.
Note:
If this sample script doesn't return your exected values, can you provide the detailed sample input values and the sample output values? By this, I would like to confirm it.
References:
reduce()
sort()
I would like to capture the name of the speaker and the comment that was made. I've tried using several different variations of ([-]{5,}\s\S+), but this doesn't seem to do the tricky. Ideally, I would like to end up with the following:
var data = [
{
name: "Operator",
comment: "Ladies and gentlemen, thank you for standing by. Welcome to the 3M First Quarter Earnings Conference Call. (Operator Instructions) As a reminder, this conference is being recorded, Thursday, April 25, 2019. I would now like to turn the call over to Bruce Jermeland, Vice President of Investor Relations at 3M."
},
{
name: "Bruce Jermeland, 3M Company - Director of IR",
comment: "Thank you, and good morning, everyone. Welcome to our first quarter 2019 business review. With me today are Mike Roman, 3M's Chief Executive Officer; and Nick Gangestad, our Chief Financial Officer. Mike and Nick will make some formal comments, and then we'll take your questions. Please note that today's earnings release and slide presentation accompanying this call are posted on our Investor Relations website at 3m.com under the heading, Quarterly Earnings. Please turn to Slide 2. Before we begin, let me remind you to mark your calendars for our upcoming earnings calls on July 25 and October 24. Please take a moment to read the forward-looking statement on Slide 3. During today's conference call, we will make certain predictive statements that reflect our current views about 3M's future performance and financial results. These statements are based on certain assumptions and expectations of future events that are subject to risks and uncertainties. Item 1A of our most recent Form 10-K lists some of the most important risk factors that could cause actual results to differ from our predictions. Finally, please note that throughout today's presentation, we will be making references to certain non-GAAP financial measures, in particular, measures which exclude the impact of the Tax Cuts and Jobs Act and significant litigation-related charges. Reconciliations of the non-GAAP measures can be found in the appendix of today's presentation and press release. Please turn to Slide 4, and I'll hand it off to Mike. Mike?"
},
...
]
How can I accomplish this?
var text = `Q1 2019 3M Co Earnings Call
ST. PAUL Apr 27, 2019 (Thomson StreetEvents) -- Edited Transcript of 3M Co earnings conference call or presentation Thursday, April 25, 2019 at 1:00:00pm GMT
TEXT version of Transcript
================================================================================
Corporate Participants
================================================================================
* Bruce Jermeland
3M Company - Director of IR
* Michael F. Roman
3M Company - CEO & Director
* Nicholas C. Gangestad
3M Company - Senior VP & CFO
================================================================================
Conference Call Participants
================================================================================
* Andrew Alec Kaplowitz
Citigroup Inc, Research Division - MD and U.S. Industrial Sector Head
* Andrew Burris Obin
BofA Merrill Lynch, Research Division - MD
* Charles Stephen Tusa
JP Morgan Chase & Co, Research Division - MD
* Deane Michael Dray
RBC Capital Markets, LLC, Research Division - Analyst
* John Fred Walsh
Crédit Suisse AG, Research Division - Director
* John George Inch
Gordon Haskett Research Advisors - MD & Senior Analyst of Multi-Industrials
* Joseph Alfred Ritchie
Goldman Sachs Group Inc., Research Division - VP & Lead Multi-Industry Analyst
* Joshua Charles Pokrzywinski
Morgan Stanley, Research Division - Equity Analyst
* Julian C.H. Mitchell
Barclays Bank PLC, Research Division - Research Analyst
* Laurence Alexander
Jefferies LLC, Research Division - VP & Equity Research Analyst
* Nigel Edward Coe
Wolfe Research, LLC - MD & Senior Research Analyst
* Scott Reed Davis
Melius Research LLC - Founding Partner, Chairman, CEO & Research Analyst of Multi-Industry Research
================================================================================
Presentation
--------------------------------------------------------------------------------
Operator [1]
--------------------------------------------------------------------------------
Ladies and gentlemen, thank you for standing by. Welcome to the 3M First Quarter Earnings Conference Call. (Operator Instructions) As a reminder, this conference is being recorded, Thursday, April 25, 2019.
I would now like to turn the call over to Bruce Jermeland, Vice President of Investor Relations at 3M.
--------------------------------------------------------------------------------
Bruce Jermeland, 3M Company - Director of IR [2]
--------------------------------------------------------------------------------
Thank you, and good morning, everyone. Welcome to our first quarter 2019 business review. With me today are Mike Roman, 3M's Chief Executive Officer; and Nick Gangestad, our Chief Financial Officer. Mike and Nick will make some formal comments, and then we'll take your questions.
Please note that today's earnings release and slide presentation accompanying this call are posted on our Investor Relations website at 3m.com under the heading, Quarterly Earnings. Please turn to Slide 2.
Before we begin, let me remind you to mark your calendars for our upcoming earnings calls on July 25 and October 24. Please take a moment to read the forward-looking statement on Slide 3.
During today's conference call, we will make certain predictive statements that reflect our current views about 3M's future performance and financial results. These statements are based on certain assumptions and expectations of future events that are subject to risks and uncertainties. Item 1A of our most recent Form 10-K lists some of the most important risk factors that could cause actual results to differ from our predictions.
Finally, please note that throughout today's presentation, we will be making references to certain non-GAAP financial measures, in particular, measures which exclude the impact of the Tax Cuts and Jobs Act and significant litigation-related charges. Reconciliations of the non-GAAP measures can be found in the appendix of today's presentation and press release.
Please turn to Slide 4, and I'll hand it off to Mike. Mike?
--------------------------------------------------------------------------------
Operator [87]
--------------------------------------------------------------------------------
Ladies and gentlemen, that does conclude the conference call for today. We thank you for your participation and ask that you please disconnect your lines.`;
console.log(text);
You could use a capturing group and for the match of the speaker use a character class and specify what characters you would allow for the name and repeat that with a space in between.
Then match the line with only hyphens followed by using a second capturing group matching the following content until you encounter the next line that starts with a hyphen. (Or multiple if you want to make it more specific.
^[ \t]*(\w+(?:[ \t]+[\w,-]+)*)[\t ]+\[\d+\]\r?\n-+\s+((?:(?:\r?\n)?(?!-).*)*)
Explanation
^ Start of string
[ \t]* Match 0+ tabs/spaces
( Capture group 1
\w+(?:[ \t]+[\w,-]+)* Match 1+ word char and repeat 0+ times matching 1+ tabs/spaces and a character class where you could specify what you would allow to match.
) Close group 1
[\t ]+\[\d+\] Match 1+ tabs/spaces, the 1+ digits between [..]
\r?\n-+\s+ Match newline, 1+ times a hyphen followed by 1+ times a whitespace char (which will also match the prepended spaces before the start of the comment)
( Capture group 2
(?: Non capturing group
(?:\r?\n)?(?!-).* Match optional newline, assert what is on the right is not a hyphen, then match the rest of the line.
)* Close non capturing group and repeat 0+ times
)Close group 2
Regex demo
var str = `Q1 2019 3M Co Earnings Call
ST. PAUL Apr 27, 2019 (Thomson StreetEvents) -- Edited Transcript of 3M Co earnings conference call or presentation Thursday, April 25, 2019 at 1:00:00pm GMT
TEXT version of Transcript
================================================================================
Corporate Participants
================================================================================
* Bruce Jermeland
3M Company - Director of IR
* Michael F. Roman
3M Company - CEO & Director
* Nicholas C. Gangestad
3M Company - Senior VP & CFO
================================================================================
Conference Call Participants
================================================================================
* Andrew Alec Kaplowitz
Citigroup Inc, Research Division - MD and U.S. Industrial Sector Head
* Andrew Burris Obin
BofA Merrill Lynch, Research Division - MD
* Charles Stephen Tusa
JP Morgan Chase & Co, Research Division - MD
* Deane Michael Dray
RBC Capital Markets, LLC, Research Division - Analyst
* John Fred Walsh
Crédit Suisse AG, Research Division - Director
* John George Inch
Gordon Haskett Research Advisors - MD & Senior Analyst of Multi-Industrials
* Joseph Alfred Ritchie
Goldman Sachs Group Inc., Research Division - VP & Lead Multi-Industry Analyst
* Joshua Charles Pokrzywinski
Morgan Stanley, Research Division - Equity Analyst
* Julian C.H. Mitchell
Barclays Bank PLC, Research Division - Research Analyst
* Laurence Alexander
Jefferies LLC, Research Division - VP & Equity Research Analyst
* Nigel Edward Coe
Wolfe Research, LLC - MD & Senior Research Analyst
* Scott Reed Davis
Melius Research LLC - Founding Partner, Chairman, CEO & Research Analyst of Multi-Industry Research
================================================================================
Presentation
--------------------------------------------------------------------------------
Operator [1]
--------------------------------------------------------------------------------
Ladies and gentlemen, thank you for standing by. Welcome to the 3M First Quarter Earnings Conference Call. (Operator Instructions) As a reminder, this conference is being recorded, Thursday, April 25, 2019.
I would now like to turn the call over to Bruce Jermeland, Vice President of Investor Relations at 3M.
--------------------------------------------------------------------------------
Bruce Jermeland, 3M Company - Director of IR [2]
--------------------------------------------------------------------------------
Thank you, and good morning, everyone. Welcome to our first quarter 2019 business review. With me today are Mike Roman, 3M's Chief Executive Officer; and Nick Gangestad, our Chief Financial Officer. Mike and Nick will make some formal comments, and then we'll take your questions.
Please note that today's earnings release and slide presentation accompanying this call are posted on our Investor Relations website at 3m.com under the heading, Quarterly Earnings. Please turn to Slide 2.
Before we begin, let me remind you to mark your calendars for our upcoming earnings calls on July 25 and October 24. Please take a moment to read the forward-looking statement on Slide 3.
During today's conference call, we will make certain predictive statements that reflect our current views about 3M's future performance and financial results. These statements are based on certain assumptions and expectations of future events that are subject to risks and uncertainties. Item 1A of our most recent Form 10-K lists some of the most important risk factors that could cause actual results to differ from our predictions.
Finally, please note that throughout today's presentation, we will be making references to certain non-GAAP financial measures, in particular, measures which exclude the impact of the Tax Cuts and Jobs Act and significant litigation-related charges. Reconciliations of the non-GAAP measures can be found in the appendix of today's presentation and press release.
Please turn to Slide 4, and I'll hand it off to Mike. Mike?
--------------------------------------------------------------------------------
Operator [87]
--------------------------------------------------------------------------------
Ladies and gentlemen, that does conclude the conference call for today. We thank you for your participation and ask that you please disconnect your lines.`;
var m;
var data = [];
var regex = /^[ \t]*(\w+(?:[ \t]+[\w,-]+)*)[\t ]+\[\d+\]\r?\n-+\s+((?:(?:\r?\n)?(?!-).*)*)/mg;
while ((m = regex.exec(str)) !== null) {
// This is necessary to avoid infinite loops with zero-width matches
if (m.index === regex.lastIndex) {
regex.lastIndex++;
}
data.push({
"name": m[1],
"comment": m[2]
});
}
console.log(data);
Seems like you can just split by /-{5,}/ and trim the parts :
var text = `Q1 2019 3M Co Earnings Call
ST. PAUL Apr 27, 2019 (Thomson StreetEvents) -- Edited Transcript of 3M Co earnings conference call or presentation Thursday, April 25, 2019 at 1:00:00pm GMT
TEXT version of Transcript
================================================================================
Corporate Participants
================================================================================
* Bruce Jermeland
3M Company - Director of IR
* Michael F. Roman
3M Company - CEO & Director
* Nicholas C. Gangestad
3M Company - Senior VP & CFO
================================================================================
Conference Call Participants
================================================================================
* Andrew Alec Kaplowitz
Citigroup Inc, Research Division - MD and U.S. Industrial Sector Head
* Andrew Burris Obin
BofA Merrill Lynch, Research Division - MD
* Charles Stephen Tusa
JP Morgan Chase & Co, Research Division - MD
* Deane Michael Dray
RBC Capital Markets, LLC, Research Division - Analyst
* John Fred Walsh
Crédit Suisse AG, Research Division - Director
* John George Inch
Gordon Haskett Research Advisors - MD & Senior Analyst of Multi-Industrials
* Joseph Alfred Ritchie
Goldman Sachs Group Inc., Research Division - VP & Lead Multi-Industry Analyst
* Joshua Charles Pokrzywinski
Morgan Stanley, Research Division - Equity Analyst
* Julian C.H. Mitchell
Barclays Bank PLC, Research Division - Research Analyst
* Laurence Alexander
Jefferies LLC, Research Division - VP & Equity Research Analyst
* Nigel Edward Coe
Wolfe Research, LLC - MD & Senior Research Analyst
* Scott Reed Davis
Melius Research LLC - Founding Partner, Chairman, CEO & Research Analyst of Multi-Industry Research
================================================================================
Presentation
--------------------------------------------------------------------------------
Operator [1]
--------------------------------------------------------------------------------
Ladies and gentlemen, thank you for standing by. Welcome to the 3M First Quarter Earnings Conference Call. (Operator Instructions) As a reminder, this conference is being recorded, Thursday, April 25, 2019.
I would now like to turn the call over to Bruce Jermeland, Vice President of Investor Relations at 3M.
--------------------------------------------------------------------------------
Bruce Jermeland, 3M Company - Director of IR [2]
--------------------------------------------------------------------------------
Thank you, and good morning, everyone. Welcome to our first quarter 2019 business review. With me today are Mike Roman, 3M's Chief Executive Officer; and Nick Gangestad, our Chief Financial Officer. Mike and Nick will make some formal comments, and then we'll take your questions.
Please note that today's earnings release and slide presentation accompanying this call are posted on our Investor Relations website at 3m.com under the heading, Quarterly Earnings. Please turn to Slide 2.
Before we begin, let me remind you to mark your calendars for our upcoming earnings calls on July 25 and October 24. Please take a moment to read the forward-looking statement on Slide 3.
During today's conference call, we will make certain predictive statements that reflect our current views about 3M's future performance and financial results. These statements are based on certain assumptions and expectations of future events that are subject to risks and uncertainties. Item 1A of our most recent Form 10-K lists some of the most important risk factors that could cause actual results to differ from our predictions.
Finally, please note that throughout today's presentation, we will be making references to certain non-GAAP financial measures, in particular, measures which exclude the impact of the Tax Cuts and Jobs Act and significant litigation-related charges. Reconciliations of the non-GAAP measures can be found in the appendix of today's presentation and press release.
Please turn to Slide 4, and I'll hand it off to Mike. Mike?
--------------------------------------------------------------------------------
Operator [87]
--------------------------------------------------------------------------------
Ladies and gentlemen, that does conclude the conference call for today. We thank you for your participation and ask that you please disconnect your lines.`;
var data = [], parts = text.split(/-{5,}/);
for (var i = 1; i < parts.length; i += 2)
data.push({ name: parts[i].split('[')[0].trim(), comment: parts[i + 1].trim() });
console.log(data);
A regex like /-{5,}(.*?)-{5,}(.*?)(?:-{5}|$)/gs will capture both the speaker and the spoken text (it will only break if the spoken text / speaker name contain more then 4 dashes after each other -----)
regex101 demo
Explanation:
-{5,} will match the first row of ----s, before the speaker name
(.*?) captures the speaker name
-{5,} matches the second row of ----s, the separator between speaker <-> spoken text
(.*?) captures the spoken text
(?:-{5}|$) matches either the end of the file or five dashes -----. (this leaves enough dashes for the first part of this regex to match again for the next speaker)
Example:
function sanitizeName(name) {
// trim it and remove the " [12]" after the name
return name.replace(/\s*\[\d+\]\s*$/, '').trim();
}
function parseConversation(text) {
let regex = /-{5,}(.*?)-{5,}(.*?)(?:-{5}|$)/gs;
let lines = [];
let match;
do {
match = regex.exec(text);
if (match) {
lines.push({
name: sanitizeName(match[1]),
comment: match[2].trim()
});
}
} while (match);
return lines;
}
let text = `Q1 2019 3M Co Earnings Call
ST. PAUL Apr 27, 2019 (Thomson StreetEvents) -- Edited Transcript of 3M Co earnings conference call or presentation Thursday, April 25, 2019 at 1:00:00pm GMT
TEXT version of Transcript
================================================================================
Corporate Participants
================================================================================
* Bruce Jermeland
3M Company - Director of IR
* Michael F. Roman
3M Company - CEO & Director
* Nicholas C. Gangestad
3M Company - Senior VP & CFO
================================================================================
Conference Call Participants
================================================================================
* Andrew Alec Kaplowitz
Citigroup Inc, Research Division - MD and U.S. Industrial Sector Head
* Andrew Burris Obin
BofA Merrill Lynch, Research Division - MD
* Charles Stephen Tusa
JP Morgan Chase & Co, Research Division - MD
* Deane Michael Dray
RBC Capital Markets, LLC, Research Division - Analyst
* John Fred Walsh
Crédit Suisse AG, Research Division - Director
* John George Inch
Gordon Haskett Research Advisors - MD & Senior Analyst of Multi-Industrials
* Joseph Alfred Ritchie
Goldman Sachs Group Inc., Research Division - VP & Lead Multi-Industry Analyst
* Joshua Charles Pokrzywinski
Morgan Stanley, Research Division - Equity Analyst
* Julian C.H. Mitchell
Barclays Bank PLC, Research Division - Research Analyst
* Laurence Alexander
Jefferies LLC, Research Division - VP & Equity Research Analyst
* Nigel Edward Coe
Wolfe Research, LLC - MD & Senior Research Analyst
* Scott Reed Davis
Melius Research LLC - Founding Partner, Chairman, CEO & Research Analyst of Multi-Industry Research
================================================================================
Presentation
--------------------------------------------------------------------------------
Operator [1]
--------------------------------------------------------------------------------
Ladies and gentlemen, thank you for standing by. Welcome to the 3M First Quarter Earnings Conference Call. (Operator Instructions) As a reminder, this conference is being recorded, Thursday, April 25, 2019.
I would now like to turn the call over to Bruce Jermeland, Vice President of Investor Relations at 3M.
--------------------------------------------------------------------------------
Bruce Jermeland, 3M Company - Director of IR [2]
--------------------------------------------------------------------------------
Thank you, and good morning, everyone. Welcome to our first quarter 2019 business review. With me today are Mike Roman, 3M's Chief Executive Officer; and Nick Gangestad, our Chief Financial Officer. Mike and Nick will make some formal comments, and then we'll take your questions.
Please note that today's earnings release and slide presentation accompanying this call are posted on our Investor Relations website at 3m.com under the heading, Quarterly Earnings. Please turn to Slide 2.
Before we begin, let me remind you to mark your calendars for our upcoming earnings calls on July 25 and October 24. Please take a moment to read the forward-looking statement on Slide 3.
During today's conference call, we will make certain predictive statements that reflect our current views about 3M's future performance and financial results. These statements are based on certain assumptions and expectations of future events that are subject to risks and uncertainties. Item 1A of our most recent Form 10-K lists some of the most important risk factors that could cause actual results to differ from our predictions.
Finally, please note that throughout today's presentation, we will be making references to certain non-GAAP financial measures, in particular, measures which exclude the impact of the Tax Cuts and Jobs Act and significant litigation-related charges. Reconciliations of the non-GAAP measures can be found in the appendix of today's presentation and press release.
Please turn to Slide 4, and I'll hand it off to Mike. Mike?
--------------------------------------------------------------------------------
Operator [87]
--------------------------------------------------------------------------------
Ladies and gentlemen, that does conclude the conference call for today. We thank you for your participation and ask that you please disconnect your lines.`;
console.log(parseConversation(text));
I am trying to send a JSON string and parse it in my server side in node js.
I want to extract specific values like title but for some reason I get undefined when I try to parse it.
This is what I tried so far.
Home.ejs
$.each(item, function(key, value)
{
var s = JSON.stringify(value);
s = s.replace(/^\s+|\s+$/g,'');
info.push(s);
});
console.log("info",info);
if (response.status == 'ok') {
$.ajax({
type: 'POST',
url: '/home',
data: JSON.stringify(info),
success: function (data) {
},
error: function (data) {
console.log('error');
console.log(data)
}
});
}
This is what it prints out in the console.
info
(20) ["{"title":"Trump ends self-made crisis","pubDate":"…tweet-restricted-super-169.jpg"},"categories":[]}", "{"title":"Intel chiefs: Trump suggested we refute …-mueller-split-4-super-169.jpg"},"categories":[]}", "{"title":"New details emerge in US destroyer colli…ald-damaged-0617-super-169.jpg"},"categories":[]}", "{"title":"Former US government worker charged with…dana-boente-0510-super-169.jpg"},"categories":[]}", "{"title":"Sniper hits ISIS target from over 2 mile…110754-isis-flag-super-169.png"},"categories":[]}", "{"title":"Grenfell Tower blaze: Other London high-…london-fire-0614-super-169.jpg"},"categories":[]}", "{"title":"Prime Minister May offer: EU citizens ca…2344-theresa-may-super-169.jpg"},"categories":[]}", "{"title":"Ousted South Korean president's confidan…outh-korea-court-super-169.jpg"},"categories":[]}", "{"title":"Why neither North Korea nor the United S…k-in-photos-0421-super-169.jpg"},"categories":[]}", "{"title":"Warmbier funeral: 2,500 celebrate kid wh…ier-funeral-0622-super-169.jpg"},"categories":[]}", "{"title":"US, Japan missile interception test fail…issile-launch-02-super-169.jpg"},"categories":[]}", "{"title":"US officials: North Korea tested rocket …ek-in-photo-0519-super-169.jpg"},"categories":[]}", "{"title":"Zuckerberg: Why Facebook's mission chang…-interview-color-super-169.jpg"},"categories":[]}", "{"title":"Fitness model dies after freak kitchen a…burger-instagram-super-169.jpg"},"categories":[]}", "{"title":"Tropical Storm Cindy brings rain, wind t…ig-tbkl-00001316-super-169.jpg"},"categories":[]}", "{"title":"Taliban claim car bomb that killed 30","…an-car-bomb-0622-super-169.jpg"},"categories":[]}", "{"title":"The images Saudi Arabia doesn't want you…war-malnutrition-super-169.jpg"},"categories":[]}", "{"title":"Fact Check: Has Trump created 33,000 min…ig-alee-00003930-super-169.jpg"},"categories":[]}", "{"title":"What do young Indians think of Donald Tr…trump-modi-split-super-169.jpg"},"categories":[]}", "{"title":"Obama blasts Republican health care bill…5-obama-montreal-super-169.jpg"},"categories":[]}"]
0
:
"{"title":"Trump ends self-made crisis","pubDate":"2017-06-22 22:36:00","link":"http://www.cnn.com/2017/06/22/politics/trump-comey-tapes-recordings-white-house/index.html","guid":"http://www.cnn.com/2017/06/22/politics/trump-comey-tapes-recordings-white-house/index.html","author":"","thumbnail":"","description":"President Donald Trump finally, grudgingly, had no choice but to come clean.","content":"President Donald Trump finally, grudgingly, had no choice but to come clean.","enclosure":{"link":"http://i2.cdn.turner.com/cnnnext/dam/assets/170622175804-trump-tweet-restricted-super-169.jpg"},"categories":[]}"
1
:
"{"title":"Intel chiefs: Trump suggested we refute Russia collusion","pubDate":"2017-06-22 10:47:14","link":"http://www.cnn.com/collections/intel-intl/","guid":"http://www.cnn.com/collections/intel-intl/","author":"","thumbnail":"","description":"","content":"","enclosure":{"link":"http://i2.cdn.turner.com/cnnnext/dam/assets/170622120332-trump-mueller-split-4-super-169.jpg"},"categories":[]}"
2
:
"{"title":"New details emerge in US destroyer collision investigation","pubDate":"2017-06-22 23:31:38","link":"http://www.cnn.com/2017/06/22/politics/uss-fitzgerald-investigation-update/index.html","guid":"http://www.cnn.com/2017/06/22/politics/uss-fitzgerald-investigation-update/index.html","author":"","thumbnail":"","description":"Five of the seven Navy sailors who died aboard the USS Fitzgerald when it collided with a cargo ship off the east coast of Japan may have been almost instantly \"incapacitated\" and died quickly, according to a very preliminary Navy analysis, a defense official told CNN.","content":"Five of the seven Navy sailors who died aboard the USS Fitzgerald when it collided with a cargo ship off the east coast of Japan may have been almost instantly \"incapacitated\" and died quickly, according to a very preliminary Navy analysis, a defense official told CNN.","enclosure":{"link":"http://i2.cdn.turner.com/cnnnext/dam/assets/170617081911-07-uss-fitzgerald-damaged-0617-super-169.jpg"},"categories":[]}"
3
:
"{"title":"Former US government worker charged with giving top-secret info to China","pubDate":"2017-06-22 23:13:14","link":"http://www.cnn.com/2017/06/22/politics/top-secret-information-china/index.html","guid":"http://www.cnn.com/2017/06/22/politics/top-secret-information-china/index.html","author":"","thumbnail":"","description":"The Justice Department announced Thursday that it had arrested and charged a former US government employee for sharing top-secret information with a Chinese government agent.","content":"The Justice Department announced Thursday that it had arrested and charged a former US government employee for sharing top-secret information with a Chinese government agent.","enclosure":{"link":"http://i2.cdn.turner.com/cnnnext/dam/assets/170510133509-dana-boente-0510-super-169.jpg"},"categories":[]}"
4
:
"{"title":"Sniper hits ISIS target from over 2 miles away","pubDate":"2017-06-23 00:54:32","link":"http://www.cnn.com/2017/06/22/politics/canadian-sniper-record-shot-isis/index.html","guid":"http://www.cnn.com/2017/06/22/politics/canadian-sniper-record-shot-isis/index.html","author":"","thumbnail":"","description":"A Canadian special operations sniper successfully hit an ISIS fighter from a record-breaking distance of more than two miles away while assisting Iraqi forces in the push to retake Mosul, according to Canadian Special Operations Command.","content":"A Canadian special operations sniper successfully hit an ISIS fighter from a record-breaking distance of more than two miles away while assisting Iraqi forces in the push to retake Mosul, according to Canadian Special Operations Command.","enclosure":{"link":"http://i2.cdn.turner.com/cnnnext/dam/assets/160618110754-isis-flag-super-169.png"},"categories":[]}"
5
:
"{"title":"Grenfell Tower blaze: Other London high-rises 'combustible'","pubDate":"2017-06-23 02:40:44","link":"http://www.cnn.com/2017/06/22/europe/grenfell-tower-fire-theresa-may/index.html","guid":"http://www.cnn.com/2017/06/22/europe/grenfell-tower-fire-theresa-may/index.html","author":"","thumbnail":"","description":"Initial tests on cladding in a number of tower blocks in London have come back as combustible, British Prime Minister Theresa May told the House of Commons Thursday during a statement about last week's fatal Grenfell Tower blaze.","content":"Initial tests on cladding in a number of tower blocks in London have come back as combustible, British Prime Minister Theresa May told the House of Commons Thursday during a statement about last week's fatal Grenfell Tower blaze.","enclosure":{"link":"http://i2.cdn.turner.com/cnnnext/dam/assets/170614142852-45-london-fire-0614-super-169.jpg"},"categories":[]}"
6
:
"{"title":"Prime Minister May offer: EU citizens can stay in UK","pubDate":"2017-06-23 02:06:22","link":"http://www.cnn.com/2017/06/22/europe/theresa-may-brexit-rights/index.html","guid":"http://www.cnn.com/2017/06/22/europe/theresa-may-brexit-rights/index.html","author":"","thumbnail":"","description":"In a Brexit divorce deal offering, British Prime Minister Theresa May on Thursday said European Union citizens would be allowed to stay in the United Kingdom after the country leaves the EU.","content":"In a Brexit divorce deal offering, British Prime Minister Theresa May on Thursday said European Union citizens would be allowed to stay in the United Kingdom after the country leaves the EU.","enclosure":{"link":"http://i2.cdn.turner.com/cnnnext/dam/assets/170620152344-theresa-may-super-169.jpg"},"categories":[]}"
7
:
"{"title":"Ousted South Korean president's confidante sentenced to 3 years","pubDate":"2017-06-23 05:53:19","link":"http://www.cnn.com/2017/06/22/asia/south-korea-choi-soon-sil/index.html","guid":"http://www.cnn.com/2017/06/22/asia/south-korea-choi-soon-sil/index.html","author":"","thumbnail":"","description":"The confidante of former South Korean President Park Geun-hye has been sentenced to three years in prison for soliciting favors for her daughter, a press officer from the Seoul Central District Court told CNN Friday.","content":"The confidante of former South Korean President Park Geun-hye has been sentenced to three years in prison for soliciting favors for her daughter, a press officer from the Seoul Central District Court told CNN Friday.","enclosure":{"link":"http://i2.cdn.turner.com/cnnnext/dam/assets/161219150546-01-choi-soon-sil-south-korea-court-super-169.jpg"},"categories":[]}"
8
:
"{"title":"Why neither North Korea nor the United States want all-out war","pubDate":"2017-06-23 05:50:20","link":"http://www.cnn.com/2017/06/22/asia/north-korea-war-devastation/index.html","guid":"http://www.cnn.com/2017/06/22/asia/north-korea-war-devastation/index.html","author":"","thumbnail":"","description":"It's been a tense six months on the Korean Peninsula and many North Korea watchers believe the situation is dangerous.","content":"It's been a tense six months on the Korean Peninsula and many North Korea watchers believe the situation is dangerous.","enclosure":{"link":"http://i2.cdn.turner.com/cnnnext/dam/assets/170420182131-05-week-in-photos-0421-super-169.jpg"},"categories":[]}"
9
:
"{"title":"Warmbier funeral: 2,500 celebrate kid who would've 'set the world on fire'","pubDate":"2017-06-22 16:55:31","link":"http://www.cnn.com/collections/intl-warmbier-funeral/","guid":"http://www.cnn.com/collections/intl-warmbier-funeral/","author":"","thumbnail":"","description":"","content":"","enclosure":{"link":"http://i2.cdn.turner.com/cnnnext/dam/assets/170622152959-08-otto-warmbier-funeral-0622-super-169.jpg"},"categories":[]}"
10
:
"{"title":"US, Japan missile interception test fails","pubDate":"2017-06-23 03:05:10","link":"http://www.cnn.com/2017/06/22/politics/us-missile-intercept-test-fails/index.html","guid":"http://www.cnn.com/2017/06/22/politics/us-missile-intercept-test-fails/index.html","author":"","thumbnail":"","description":"A US and Japanese missile test conducted in Hawaii missed its target, but both militaries stopped short of calling it a failure.","content":"A US and Japanese missile test conducted in Hawaii missed its target, but both militaries stopped short of calling it a failure.","enclosure":{"link":"http://i2.cdn.turner.com/cnnnext/dam/assets/170206111347-standard-missile-launch-02-super-169.jpg"},"categories":[]}"
11
:
"{"title":"US officials: North Korea tested rocket engine","pubDate":"2017-06-22 23:31:27","link":"http://www.cnn.com/videos/world/2017/06/22/north-korea-tests-rocket-todd-dnt-tsr.cnn","guid":"http://www.cnn.com/videos/world/2017/06/22/north-korea-tests-rocket-todd-dnt-tsr.cnn","author":"","thumbnail":"","description":"Tensions between the US and North Korea continue to rise after North Korea tested a rocket engine, according to US officials. CNN's Brian Todd reports.","content":"Tensions between the US and North Korea continue to rise after North Korea tested a rocket engine, according to US officials. CNN's Brian Todd reports.","enclosure":{"link":"http://i2.cdn.turner.com/cnnnext/dam/assets/170518180155-09-week-in-photo-0519-super-169.jpg"},"categories":[]}"
12
:
"{"title":"Zuckerberg: Why Facebook's mission changed","pubDate":"2017-06-22 20:06:19","link":"http://money.cnn.com/2017/06/22/technology/facebook-zuckerberg-interview/index.html","guid":"http://money.cnn.com/2017/06/22/technology/facebook-zuckerberg-interview/index.html","author":"","thumbnail":"","description":"","content":"","enclosure":{"link":"http://i2.cdn.turner.com/cnnnext/dam/assets/170622131016-02-zuckerberg-interview-color-super-169.jpg"},"categories":[]}"
13
:
"{"title":"Fitness model dies after freak kitchen accident, family says","pubDate":"2017-06-22 19:15:18","link":"http://www.cnn.com/2017/06/22/world/rebecca-burger-whipped-cream-instagram-fitness-model-death-trnd/index.html","guid":"http://www.cnn.com/2017/06/22/world/rebecca-burger-whipped-cream-instagram-fitness-model-death-trnd/index.html","author":"","thumbnail":"","description":"A popular social media fitness personality died after what can only be described as a freak accident involving a whipped cream canister.","content":"A popular social media fitness personality died after what can only be described as a freak accident involving a whipped cream canister.","enclosure":{"link":"http://i2.cdn.turner.com/cnnnext/dam/assets/170622112522-0622-rebecca-burger-instagram-super-169.jpg"},"categories":[]}"
14
:
"{"title":"Tropical Storm Cindy brings rain, wind to Gulf Coast","pubDate":"2017-06-22 22:24:14","link":"http://www.cnn.com/videos/us/2017/06/22/tropical-storm-cindy-orig-tbkl.cnn","guid":"http://www.cnn.com/videos/us/2017/06/22/tropical-storm-cindy-orig-tbkl.cnn","author":"","thumbnail":"","description":"Six million people are under tornado watch in Louisiana, Mississippi and Alabama.","content":"Six million people are under tornado watch in Louisiana, Mississippi and Alabama.","enclosure":{"link":"http://i2.cdn.turner.com/cnnnext/dam/assets/170622181943-tropical-storm-cindy-orig-tbkl-00001316-super-169.jpg"},"categories":[]}"
15
:
"{"title":"Taliban claim car bomb that killed 30","pubDate":"2017-06-22 14:28:56","link":"http://www.cnn.com/2017/06/22/asia/afghanistan-car-bomb/index.html","guid":"http://www.cnn.com/2017/06/22/asia/afghanistan-car-bomb/index.html","author":"","thumbnail":"","description":"At least 30 people were killed Thursday in a car bomb attack outside a bank in Lashkar Gah, the capital of Afghanistan's southern Helmand province, officials said.","content":"At least 30 people were killed Thursday in a car bomb attack outside a bank in Lashkar Gah, the capital of Afghanistan's southern Helmand province, officials said.","enclosure":{"link":"http://i2.cdn.turner.com/cnnnext/dam/assets/170622071724-01-afghanistan-car-bomb-0622-super-169.jpg"},"categories":[]}"
16
:
"{"title":"The images Saudi Arabia doesn't want you to see","pubDate":"2017-06-22 16:26:56","link":"http://www.cnn.com/2017/06/21/middleeast/yemen-malnutrition-cholera-crisis-images/index.html","guid":"http://www.cnn.com/2017/06/21/middleeast/yemen-malnutrition-cholera-crisis-images/index.html","author":"","thumbnail":"","description":"Batool Ali is six years old, though you would never guess that from her huge, haunted eyes and emaciated frame. Ribs jutting out over her distended belly, Batool weighs less than 16 kilograms (35 pounds). She is one of nearly half a million children in Yemen suffering from severe malnutrition.","content":"Batool Ali is six years old, though you would never guess that from her huge, haunted eyes and emaciated frame. Ribs jutting out over her distended belly, Batool weighs less than 16 kilograms (35 pounds). She is one of nearly half a million children in Yemen suffering from severe malnutrition.","enclosure":{"link":"http://i2.cdn.turner.com/cnnnext/dam/assets/170619144015-12-yemen-civil-war-malnutrition-super-169.jpg"},"categories":[]}"
17
:
"{"title":"Fact Check: Has Trump created 33,000 mining jobs?","pubDate":"2017-06-22 23:59:36","link":"http://www.cnn.com/videos/politics/2017/06/22/fact-check-trump-mining-orig-alee.cnn","guid":"http://www.cnn.com/videos/politics/2017/06/22/fact-check-trump-mining-orig-alee.cnn","author":"","thumbnail":"","description":"CNN's Jake Tapper, in partnership with FactCheck.org, checks a Trump claim that the President added 33,000 mining jobs since his inauguration.","content":"CNN's Jake Tapper, in partnership with FactCheck.org, checks a Trump claim that the President added 33,000 mining jobs since his inauguration.","enclosure":{"link":"http://i2.cdn.turner.com/cnnnext/dam/assets/170622195811-fact-check-trump-mining-orig-alee-00003930-super-169.jpg"},"categories":[]}"
18
:
"{"title":"What do young Indians think of Donald Trump?","pubDate":"2017-06-23 05:02:14","link":"http://www.cnn.com/2017/06/22/asia/young-indians-trump/index.html","guid":"http://www.cnn.com/2017/06/22/asia/young-indians-trump/index.html","author":"","thumbnail":"","description":"Indian Prime Minister Narendra Modi is set to meet US President Donald Trump for the first time on Monday.","content":"Indian Prime Minister Narendra Modi is set to meet US President Donald Trump for the first time on Monday.","enclosure":{"link":"http://i2.cdn.turner.com/cnnnext/dam/assets/170125123753-trump-modi-split-super-169.jpg"},"categories":[]}"
19
:
"{"title":"Obama blasts Republican health care bill","pubDate":"2017-06-23 02:11:50","link":"http://www.cnn.com/2017/06/22/politics/barack-obama-health-care-bill-reaction/index.html","guid":"http://www.cnn.com/2017/06/22/politics/barack-obama-health-care-bill-reaction/index.html","author":"","thumbnail":"","description":"President Barack Obama on Thursday spoke out against a proposed GOP Senate bill that dismantles the Affordable Care Act, also known as Obamacare.","content":"President Barack Obama on Thursday spoke out against a proposed GOP Senate bill that dismantles the Affordable Care Act, also known as Obamacare.","enclosure":{"link":"http://i2.cdn.turner.com/cnnnext/dam/assets/170606215725-obama-montreal-super-169.jpg"},"categories":[]}"
server.js
app.post("/home",function(req,res)
{
var data = (req.body);
console.log("name",data);
var news_title = [];
var news_link =[];
var news_date =[];
/*for(var i in req.body){
var item = req.body.items[i];
//console.log(item);
}*/
//console.log("name",name);
});
This is what it prints out in the console
name { '["{\"title\":\"Trump ends self-made crisis\",\"pubDate\":\"2017-06-22 22:36:00\",\"link\":\"http://www.cnn.com/2017/06/22/politics/trump-comey-tapes-recordings-white-house/index.html\",\"guid\":\"http://www.cnn.com/2017/06/22/politics/trump-comey-tapes-recordings-white-house/index.html\",\"author\":\"\",\"thumbnail\":\"\",\"description\":\"President Donald Trump finally, grudgingly, had no choice but to come clean.\",\"content\":\"President Donald Trump finally, grudgingly, had no choice but to come clean.\",\"enclosure\":{\"link\":\"http://i2.cdn.turner.com/cnnnext/dam/assets/170622175804-trump-tweet-restricted-super-169.jpg\"},\"categories\":': [ '' ] }
name { '["{\"title\":\"Trump ends self-made crisis\",\"pubDate\":\"2017-06-22 22:36:00\",\"link\":\"http://www.cnn.com/2017/06/22/politics/trump-comey-tapes-recordings-white-house/index.html\",\"guid\":\"http://www.cnn.com/2017/06/22/politics/trump-comey-tapes-recordings-white-house/index.html\",\"author\":\"\",\"thumbnail\":\"\",\"description\":\"President Donald Trump finally, grudgingly, had no choice but to come clean.\",\"content\":\"President Donald Trump finally, grudgingly, had no choice but to come clean.\",\"enclosure\":{\"link\":\"http://i2.cdn.turner.com/cnnnext/dam/assets/170622175804-trump-tweet-restricted-super-169.jpg\"},\"categories\":': [ '' ] }
I want to extract the title value but for some reason I keep getting undefined when I try req.body.title.
It looks like you are having an issue because you are using JSON.stringify on each array element and then using JSON.stringify on the compiled array.
You should get the expected outcome by stringifying the whole array without stringifying each part. i.e. in your case just stringify the item
$.ajax({
type: 'POST',
url: '/home',
data: JSON.stringify(item),
success: function (data) {
}
Given the below source text, using javascript, I need to match the below excerpt.
My Regex (what I have so far):
subject.match(/\s\([A-Z]{3}\)[\w\s]+\([A-Z]{3}\)[\s\S]*?\([A-Z]\)/)
Excerpt (match I need to get):
Atlanta (ATL) to Charlotte (CLT) — Wed, Dec 17
American Airlines Inc. 658
Dep: 5:50 am
Arr: 6:57 am
1h 7m
Airbus A321
Economy (L)
Source (group of text to get match from, taken from textarea):
Atlanta (ATL) to Cancun (CUN) — Wed, Dec 17
Long layover
Atlanta (ATL) to Charlotte (CLT) — Wed, Dec 17
American Airlines Inc. 658
Dep: 5:50 am
Arr: 6:57 am
1h 7m
Airbus A321
Economy (L)
OPERATED BY US AIRWAYS
Layover in CLT
2h 33m
Charlotte (CLT) to Cancun (CUN) — Wed, Dec 17
American Airlines Inc. 883
Dep: 9:30 am
Arr: 11:26 am
2h 56m
Boeing 767
Economy (L)
Food for Purchase
OPERATED BY US AIRWAYS
Cancun (CUN) to Atlanta (ATL) — Wed, Dec 24
Long layover
Cancun (CUN) to Miami (MIA) — Wed, Dec 24
American Airlines Inc. 1157
Dep: 12:01 pm
Arr: 2:40 pm
1h 39m
Boeing 737
Economy (G)
Layover in MIA
3h 40m
Miami (MIA) to Atlanta (ATL) — Wed, Dec 24
American Airlines Inc. 349
Dep: 6:20 pm
Arr: 8:25 pm
2h 5m
Boeing 737
Economy (G)
My problem: my regex matches from the wrong starting point when certain lines are duplicated in the source text. See screenshot below taken from RegexBuddy's test panel for a better explanation.
How can I change my regex to match starting at the point indicated?
I solved that problem with this:
subject.match(/\s\([A-Z]{3}\)[\w\s]+\([A-Z]{3}\).*\n(?:.{3,}\n)*.*\([A-Z]\)/)
Just completed the first line with non newline elements (0 or more), then matched a newline (just 1), and then matched all lines with length of 3 or more, untill last (had to fill it too).
PD: There's a non capturing group there, harmless.
One of the problems of your regex is that you allowed anything, including the newlines, before the second right parenthesis. That's causing the ending match to the string "(L)". If you can include in your requirements that at least three lines of text are needed to start a match, then the following may work for you:
subject.match(/\s\([A-Z]{3}\)[^\r\n]+\([A-Z]{3}\)([^\r\n]+[\r\n]){3,}/);
I have a database, where I am getting time-stamps (millisecond) along with price values and trying to plot them on a "HighStock" chart.
I was told to, instead of just letting the exact date show up on the y-axis, have the y-axis show only on a month-by-month basis. The problem is that I have an array of arrays (the format, and the only format I'm aware of, that HighStock accepts) with time-stamps which end up being interpreted by exact date (as I would expect).
I thought about just modifying the time-stamps myself based on month (I already have JavaScript functions that can convert time-stamps to dates and vice versa), but then I would get something like Monday, Jul 1, 2013 -- Thursday, Aug 1, 2013 etc. Of course, the Jul 1 or Aug 1 could be converted to whatever date I grouped by in the time-stamp, but I really would need to take that out entirely and have it say just Jul and Aug. I'm sure this is possible, given the never-ending plethora of options HighCharts/HighStock has, but I am out of options on where to look.
With the help of the following sites:
http://api.highcharts.com/highcharts
http://api.highcharts.com/highstock
And trying things myself, I have learned a bit about what some of the options do, but I am no closer to my original goal.
I have looked in plotOptions, xAxis, and others (where I would think they might be) but I am on the verge of giving up. The documentation on these sites are very helpful, but it is not always clear what they do, or what syntax they expect.
Whether there's an easy way to this with HighCharts/HighStock options using the original time-stamps alone, or whether I need to convert every time-stamp to a date, compare months while adding values together, then re-converting back into a time-stamp, and finding a chart option which omits all but the month and year, I have to get this done. Any help is greatly appreciated.
Here's an example from the Highcharts API Reference page.
If you have categories like this, for example:
categories: ['Jan 1', 'Feb 1', 'Mar 1', 'Apr 1', 'May 1', 'Jun 1', 'Jul 1', 'Aug 1', 'Sep 1', 'Oct 1', 'Nov 1', 'Dec 1']
You can use this type of config for the xAxis label:
xAxis: {
categories: ['Jan 1', 'Feb 1', 'Mar 1', 'Apr 1', 'May 1', 'Jun 1', 'Jul 1', 'Aug 1', 'Sep 1', 'Oct 1', 'Nov 1', 'Dec 1'],
labels: {
formatter: function () {
return this.value.substring(0,3); // - formatted return value
//return this.value; // - default return value
}
}
},
Here's a Fiddle that you can mess around with to show you exactly how it works: Click Here.