问题
In Visual Studio, I need to substitute a word with another, preserving the first character case. For example I need to subsitute "Bob" with "James" and "bob" with "james" at once, and I must avoid to replace partial matches like "ob" with "james" or "James".
This can be done e.g. in Notepad++ with find:"((b)|(B))ob", replace: "(?2j:?3J)ames"; unfortunately this does not work in Visual Studio (I'm using 2015). Is it possible to do this in Visual Studio? Thanks.
回答1:
It is not possible with Visual Studio regex replace feature. Use Notepad++ with your current approach, or use separate regex replacements:
Search: \bBob\b
Replace: James
and then
Search: \bbob\b
Replace: james
Note that \b
is a word boundary. If you need to replace all substrings regardless of whether Bob
or bob
are whole words, remove the \b
from the patterns.
来源:https://stackoverflow.com/questions/41298753/conditional-replace-with-visual-studio