首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Javascript:在双引号中查找双引号,无论是在开头、中间还是结尾

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

Stack Overflow用户
提问于 2020-08-19 19:55:37
回答 1查看 45关注 0票数 0

在这个问题上苦苦挣扎。

我的测试数据是:

代码语言: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, 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.""
*/

但结果仍然是错误的。一些匹配符合预期,而另一些则不匹配。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-08-19 20:12:58

尝试使用此正则表达式/""([^\""]+)""/

代码语言: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);
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.""
*/

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/63486444

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档