A regular expression like below should do the job (with \1
to reference the first capture group - your variable):
^\s*(.+?)\.Format\(.*\1.*\)
There are a few assumptions and things to note though:
I assumed that the variable is the first thing in the line, proceeded by whitespace only.
The variable is only checked to appear in brackets after
.Format
(as you put it in your question). The same variable may appear in the first parameter, the regex currently doesn't check that.You may add additional whitespace to the regex if neeeded.