简体   繁体   中英

How do I capture a substring in a Visual Studio find and replace?

I want to do a find and replace in a HTML document in Visual Studio. I have looked up the syntax, and placing a pattern inside parentheses captures and implicitly numbers the substring. This works fine.

The problem is that I then want to use the captured substring in a replace, but the replace input box appears to have no knowledge of the numbered substring captured in the find.

In find, I had \\$([a-zA-Z]+) to capture all dollar symbols followed by one or more letters. I want to replace the dollars with an apostrophe followed by the letters that were captured in the find.

Can anyone tell me how to do this, please? It seems a huge limitation to me that the capturing of substrings is not preserved from the find to the replace. What am I missing?

Use this regex, \\$(\\w+) , it's pretty much the same as yours but a little bit shorter.

Then type this for replacement '$1 . $1 is the first capture group, ie the text.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM