Basically what I need is a regex expression that only selects double-quotes that are not surrounded by single-quotes. (This is in order to quickly refactor double-quote into single-quotes without breaking any nested strings).
Example (same as here):
"foo" => 'foo'
'foo' => 'foo'
abc "foo" => abc 'foo'
foo "bar", "baz" => foo 'bar', 'baz'
abc 'foo "bar" baz' => abc 'foo "bar" baz'
So on searching for this question, I was able to find how to do this in PCRE but I wasn't able to figure out how to convert the (*SKIP)(*F)
into usable Javascript Regex
My own Javascript attempt is:
/(?:('.*["].*')|")/g
(live demo).
The first pattern /'.*["].*'/
goes a good job matching what I eventually want to exclude ('foo "bar" baz'
) but I'm then unsure how to tell the expression that if this is matched, to exclude it.
I've tried playing around with the (?!)
expression with no success.
If anyone has an idea on how to do either write a better regex or have an alternative solution to the problem I'd appreciate it.
EDIT:
As additional information, the regex expressions are being used for search and replace functions in WebStorm/PHPStorm to refactor source code.