How to match something with regex that is not between two special characters?
Assuming the quotes are correctly balanced and there are no escaped quotes, then it’s easy: result = subject.gsub(/a(?=(?:[^”]*”[^”]*”)*[^”]*\Z)/, ”) This replaces all the as with the empty string if and only if there is an even number of quotes ahead of the matched a. Explanation: a # Match a (?= # only if it’s followed … Read more