简体   繁体   中英

How can I use search replace in visual studio with regular expression?

In the find input of visual studio I have this expression

<input type="submit" value=(.*) />

And in the replace one I have

<input type="submit" value=(\1) a />

But for some reason instead of adding an "a" it is literally replacing the code.

I mean, I am getting this

<input type="submit" value=(\1) a />

instead of this

<input type="submit" value="Change password" a />

I am using Visual Studio 2012 Express for Web

In the replacement string, you need to use $1 . \\1 is for backreferences within the search pattern. You'll also want to omit the parentheses in the replacement string.

<input type="submit" value=$1 a />

To make your pattern a bit more robust you might want to use something like

<input type="submit" value=("[^"*]") />

For the pattern. Otherwise you'll get problems if you have another self-closing tag on the same line, or an input tag with more attributes.

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