Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Find and replace using regular expressions (regex) in visual studio?

I am converting from VB.net to C#.Net.

I need to replace Session("something") or Session("Others") to Session["something"] or Session["Others"] in the whole project. What regex i need to use in the find box and what's in the replace box. Any help would be appreciated.

like image 689
MJK Avatar asked May 09 '14 11:05

MJK


1 Answers

Make sure you check on the option use the regular expression.

  • Find what: Session\("{.*?}"\)
  • Replace with: Session["\1"]

Note: using lazy operator ? here is try to stop when finding the first match. Thus, it should be able to handle cases like:

  1. Session("Types") = new SelectList(xxx, "Code", "Description");
  2. ((((Session("something)))))))))"))))

P.S.: In VS2013, you should use the following instead:

  • Find what: Session\("(.*?)"\)
  • Replace with: Session["$1"]
like image 146
herohuyongtao Avatar answered Oct 29 '22 14:10

herohuyongtao