Javascript:查找双引号内的双引号,无论是在开头、中间还是结尾

Javascript: Find double quotes within double quotes, whether at the start, middle or end

正在为这个问题苦苦挣扎...

我的测试数据是:

const rawTextString = `"""In 1981, DuPont"" prepared charts and tables recording the C-8 concentrations over a multi-year period at selected ""receptors"" or locations."`

const rawTextString2 = `"In an internal document reporting on various studies, DuPont stated, ""We conclude that C-8 has weak tumorigenic activity in male rats based on a slight increase in benign testicular tumors. At the recommended 0.01 mg/m3, skin AEL, we conclude that there is no significant health hazard. Based on the four negative developmental studies, C-8 is not considered a developmental hazard. No information is available on the reproductive hazard."""`

const rawTextString3 = `"In November 1982, DuPont's Medical Director noted that DuPont did not have adequate ""knowledge of the chronic health effects from long-term exposure to low levels of"" PFOA, that PFOA ""is retained in the blood for a long time,"" that there ""is obviously great potential for current or future exposure of members of the local community from emissions from the Plant,"" and recommended that all ""available practical steps be taken to reduce this exposure.""  In addition to being aware that PFOA is bioaccumulative, DuPont was aware by 1984 at the latest that PFOA is biopersistent."`

const doubleQuoteList = rawTextString.match(/"[^"]*"[^"]*""/gmi);
console.log(doubleQuoteList);

/* 
   Expected output:
""In 1981, DuPont""

""receptors""

""We conclude that C-8 has weak tumorigenic activity in male rats based on a slight increase in benign testicular tumors. At the recommended 0.01 mg/m3, skin AEL, we conclude that there is no significant health hazard. Based on the four negative developmental studies, C-8 is not considered a developmental hazard. No information is available on the reproductive hazard."""

""knowledge of the chronic health effects from long-term exposure to low levels of""

""is retained in the blood for a long time,""

""available practical steps be taken to reduce this exposure.""
*/

但是结果还是不对。有些符合预期,有些则没有。

试试这个正则表达式 /""([^\""]+)""/

const rawTextString = `"""In 1981, DuPont"" prepared charts and tables recording the C-8 concentrations over a multi-year period at selected ""receptors"" or locations."`

const rawTextString2 = `"In an internal document reporting on various studies, DuPont stated, ""We conclude that C-8 has weak tumorigenic activity in male rats based on a slight increase in benign testicular tumors. At the recommended 0.01 mg/m3, skin AEL, we conclude that there is no significant health hazard. Based on the four negative developmental studies, C-8 is not considered a developmental hazard. No information is available on the reproductive hazard."""`

const rawTextString3 = `"In November 1982, DuPont's Medical Director noted that DuPont did not have adequate ""knowledge of the chronic health effects from long-term exposure to low levels of"" PFOA, that PFOA ""is retained in the blood for a long time,"" that there ""is obviously great potential for current or future exposure of members of the local community from emissions from the Plant,"" and recommended that all ""available practical steps be taken to reduce this exposure.""  In addition to being aware that PFOA is bioaccumulative, DuPont was aware by 1984 at the latest that PFOA is biopersistent."`

//const doubleQuoteList = rawTextString.match(/"[^"]*"[^"]*""/gmi);
const doubleQuoteList = rawTextString3.match(/""([^\""]+)""/);
console.log(doubleQuoteList);

/* 
   Expected output:
""In 1981, DuPont""

""receptors""

""We conclude that C-8 has weak tumorigenic activity in male rats based on a slight increase in benign testicular tumors. At the recommended 0.01 mg/m3, skin AEL, we conclude that there is no significant health hazard. Based on the four negative developmental studies, C-8 is not considered a developmental hazard. No information is available on the reproductive hazard."""

""knowledge of the chronic health effects from long-term exposure to low levels of""

""is retained in the blood for a long time,""

""available practical steps be taken to reduce this exposure.""
*/