As I understand, your string is something like
str = 'window.__APOLLO_STATE__ = JSON.parse("my dog has fleas");'
and you wish to extract the text between the double quotes. You can do that with the following regular expression, which does not employ a capture group:
r = /\Awindow\.__APOLLO_STATE__ = JSON\.parse\(\"\K.+?(?=\"\);\z)/
str[r]
#=> "my dog has fleas"
The regular expression can be written in free-spacing mode to make it self-documenting:
r = /
\A # match beginning of string
window\.__APOLLO_STATE__\ =\ JSON\.parse\(\"
# match substring
\K # discard everything matched so far
.+? # match 1+ characters, lazily
(?=\"\);\z) # match "); followed by end-of-string (positive lookahead)
/x # free-spacing regex definition mode
The contents of a positive lookahead must be matched but are not part of the match returned. Neither is the text matched prior to the \K
directive part of the match returned.
Free-spacing mode removes all whitespace before the expression is parsed. Accordingly, any intended spaces (in "APOLLO_STATE__ = JSON"
, for example) must be protected. I've done that by escaping the spaces, one of several ways that can be done.