gpt4 book ai didi

javascript - 使用正则表达式捕获演讲者姓名和评论

转载 作者:行者123 更新时间:2023-11-30 11:02:11 25 4
gpt4 key购买 nike

我想记录演讲者的姓名和发表的评论。我已经尝试使用 ([-]{5,}\s\S+) 的几种不同变体,但这似乎并没有解决问题。理想情况下,我希望得到以下结果:

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?"
},
...
]

我怎样才能做到这一点?

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);

最佳答案

您可以使用捕获组,并为说话者的匹配使用字符类,并指定名称中允许使用的字符,并在中间用空格重复该字符。

然后匹配仅包含连字符的行,然后使用匹配以下内容的第二个捕获组,直到遇到以连字符开头的下一行。 (或者多个,如果你想让它更具体。

^[ \t]*(\w+(?:[ \t]+[\w,-]+)*)[\t ]+\[\d+\]\r?\n-+\s+((?:(?:\r?\n)?(?!-).*)*)

解释

  • ^ 字符串开始
  • [\t]* 匹配 0+ 个制表符/空格
  • ( 捕获组 1
    • \w+(?:[\t]+[\w,-]+)* 匹配 1+ 个单词 char 并重复 0+ 次匹配 1+ 个制表符/空格和一个字符类,其中您可以指定允许匹配的内容。
  • ) 关闭第 1 组
  • [\t ]+\[\d+\] 匹配1+个制表符/空格,[..]之间的1+个数字 >
  • \r?\n-+\s+ 匹配换行符,1+ 次连字符后跟 1+ 次空白字符(这也将匹配注释开始前的前置空格)
  • ( 捕获组 2
    • (?: 非捕获组
      • (?:\r?\n)?(?!-).* 匹配可选的换行符,断言右边的不是连字符,然后匹配该行的其余部分。
    • )* 关闭非捕获组并重复0+次
  • )关闭组 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);

关于javascript - 使用正则表达式捕获演讲者姓名和评论,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57256571/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com