问题描述
正在为此奋斗...
我的测试数据是:
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,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,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.""
*/