双引号里面可能有\"这种escapsed quote,以及其他escapse的字符,比如\n\啥的。
stackoverflow搜了这个:/"(?:[^"\\]|\\.)*"/
大多数情况可以work了,大家觉得还有啥bug吗?
1
alphonsez OP 试了一下:
``` "Foo \"Bar\"", "\"^(background|background\-attachment|background\-color|background\-image|background\-position|background\-position\-x|background\-position\-y|background\-repeat|border|border\-bottom|border\-bottom\-color|border\-bottom\-style|border\-bottom\-width|border\-collapse|border\-color|border\-left|border\-left\-color|border\-left\-style|border\-left\-width|border\-right|border\-right\-color|border\-right\-style|border\-right\-width|border\-spacing|border\-style|border\-top|border\-top\-color|border\-top\-style|border\-top\-width|border\-width|bottom|clear|clip|color|cursor|direction|display|filter|float|font|font\-family|font\-size|font\-size\-adjust|font\-stretch|font\-style|font\-variant|font\-weight|height|left|letter\-spacing|line\-break|line\-height|list\-style|list\-style\-image|list\-style\-position|list\-style\-type|margin|margin\-bottom|margin\-left|margin\-right|margin\-top|marker\-offset|max\-height|max\-width|min\-height|min\-width|orphans|outline|outline\-color|outline\-style|outline\-width|overflow|overflow\-X|overflow\-Y|padding|padding\-bottom|padding\-left|padding\-right|padding\-top|position|right|size|table\-layout|text\-align|text\-align\-last|text\-decoration|text\-indent|text\-justify|text\-overflow|text\-shadow|text\-transform|text\-autospace|text\-kashida\-space|text\-underline\-position|top|vertical\-align|visibility|white\-space|widows|width|word\-break|word\-spacing|word\-wrap|writing\-mode|z\-index|zoom)$\"", "Foo \"Bar\"" ``` 发现上面的直接crash了。估计回朔太多。我搞了个Patterns应用来测的。 同一个stackoverflow页面上的这个能很好work: ```/"([^"\\]*(\\.[^"\\]*)*)"/``` 有知道为什么的吗? |