@guy038 said in A simple search and replace:
To my mind, all these statements can be solved with the two following regexes :
Regex A : (?-s)"(?:\\.|.)+"
Regex B : (?-s)"(?:\\.|.)+?"
I would use Regex B with a slight modification; the +? should be a *? to correctly handle the empty string "".
Thus, I think the simplest regex we can use for this task is probably (?-s)"(?:\\.|.)*?"
There is one important caveat here: these regexes for recognizing JSON strings will break if you start the search in the middle of a string.
For example, if you have this text
"foo" "bar"
"from\r\n\t[\"\\\"here\\\"\", \"to\", \"here\" is all one string]"
the best regex, (?-s)"(?:\\.|.)*?", will correctly identify exactly three strings in the file if you start the search at the beginning of the file.
But if you start with the caret after the word from on the second line, you will incorrectly identify "\\\"here\\\"\", \"to\", \"here\" is all one string]" as being a valid string.