如何解决Javascript:在双引号中查找双引号,无论是在开头,中间还是结尾
正在为此奋斗...
我的测试数据是:
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.""
*/
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。