I am looking for a regular expression which will match all occurrences of foo
unless it is in a \ref{..}
command. So \ref{sec:foo}
should not match.
I will probably want to add more commands for which the arguments should be excluded later so the solution should be extendable in that regard.
There are some similar questions trying to detect when something is in parenthesis, etc.
- Regex to match only commas not in parentheses?
- Split string by comma if not within square brackets or parentheses
The first has an interesting solution using alternatives: \(.*?\)|(,)
the first alternative matches the unwanted versions and the second has the match group. However, since I am using this is in a search&replace context I cannot really use match groups.