Write a regular expression to match a double-quoted string.
The string may have escaped quotes \" inside.
For example:
str = ' .. "test" .. ' // matches "test" // Slashes are escaped str = ' .. "say \\"Hello\\"!" .. ' // "say \"Hello\"!" str = ' .. "\\" .. ' // no match
Решение
Решение
The solution is /"(\\.|[^"\\])*"/.
A backslashed symbol \\. (quote or anything) is consumed before non-backslashed match attempt [^"\\].
var re = /"(\\.|[^"\\])*"/g alert( ' .. "test" .. '.match(re) ) alert( ' .. "say \\"Hello\\"!" .. '.match(re) ) alert( ' .. "\\" .. '.match(re) )
#287