Visual Studio查找和替换正则表达式帮助

Dav*_*son 38 regex replace visual-studio-2008

我想替换一些赋值语句,如:

int someNum = txtSomeNum.Text; 
int anotherNum = txtAnotherNum.Text;
Run Code Online (Sandbox Code Playgroud)

int someNum = Int32.Parse(txtSomeNum.Text);
int anotherNum = Int32.Parse(txtAnotherNum.Text);
Run Code Online (Sandbox Code Playgroud)

使用正则表达式,使用Visual Studio的查找和替换有一个很好的方法吗?我不确定正则表达式是什么.

Mar*_*ins 59

我认为在Visual Studio中,您可以使用花括号标记表达式{txtSomeNum.Text}.然后在替换中,您可以参考它\1.所以更换线就像是Int32.Parse(\1).


更新:通过@ Timothy003

VS 11取消了{}\1语法并使用()$ 1

  • 我知道这已经老了......但是为什么微软必须以自己的方式做所有事情.我用过的所有其他IDE和软件都使用()标记表达式,使用$ 1来引用它们.微软应该称这些不规则表达式 (27认同)
  • @MikeMurko VS 11取消{}\1语法并使用()$ 1.好极了! (25认同)

Dav*_*son 6

这就是我要找的东西:

查找:= {.*\.文本}

替换:= Int32.Parse(\ 1)