The string looks like this:
abc def
123 'abc' abc "def"
bla bla
So I want to replace abc with something else, but to not affect the abc that’s within quotes. Same with def, which is using double quotes…
This is actually for a string that contains SQL queries, I want to replace table names without replacing by mistake data from fields which could contain the same word.
you can use regular expressions with negative lookahead and negative lookbehind. You can read more about that here: http://www.regular-expressions.info/lookaround.html
Here is an example that matches abc:
(?<!['"])(?<target>abc)(?!['"])– this will match any abc not surrounded by single or double quotes.