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

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.

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:
Session("Types") = new SelectList(xxx, "Code", "Description");
((((Session("something)))))))))"))))
P.S.: In VS2013, you should use the following instead:
Find what: Session\("(.*?)"\)
Replace with: Session["$1"]

Related

Netbeans regular expression search and replace

I would like to find and replace in project on netbeans by using regular expression.
Find
$_SESSION['anything']['anything']
Replace with
$this->Session->read('anything.anything');
Please help.
You could accomplish this in the following way ...
Find \$_SESSION\['(.*?)'\]\['(.*?)'\]
Replace with \$this->Session->read('$1.$2');
see regex demo / explanation

using regexp in visual studio 2010 to find and replace attributes

i have a regexp (c|C)(lass)="([A-Za-z0-9_-]\s)(popup)(\s[A-Za-z0-9_-])" that will return the class attribute with a value of popup inside.
I am having difficulty to get this to run in the visual studio 2010 find and replace. Ultimately i would like to replace the popup with another class name lets say im-with-stupid
My first issue is with running the find returning Grouped expression is missing ')'. My assumption is the error is caused by the ". How can i escape this in the search.
Bonus points for the replace regexp - sorry i cant get that far to make an example code yet.
VS2010:
Find What:
{[cC]lass="[A-Za-z0-9_\-]+ }popup{ [A-Za-z0-9_\-]+"}
Replace with:
\1im-with-stupid\2
Find options:
Use Regular expressions
VS2012:
Find What:
([cC]lass="\w+\s)popup(\s\w+")
Replace with:
$1im-with-stupid$2
Find options:
Use Regular expressions

Regex to modify an html tag

I am trying to replace
<legend>my legend</legend>
with
<legend><span>my legend</span></legend>
Intellij/Webstorm,supports regexp match and replace.
I tried along the examples here, but didn't work.
Any help on a regexp to find and replace as described above is appreciated.
I use mac, so gnu command line tools also an option (sed,..)
Thanks.
Use replace with the following regular expression:
<legend>([^<]*)</legend>
and replacement
<legend><span>$1</span></legend>

To lower case using Find and Replace with regular expression in Visual Studio 2010

I am using the Find and Replace function in Visual Studio 2010 in order to change the coding style for fields.
All instances similar to
m_MyField
should be
_myField
but I can only manage to get
_MyField
using
Find what: m_{[a-zA-Z]}
Replace with: _\1
How do I make the first letter lower case? I have tried the following but it does not work:
Find what: m_{[a-zA-Z]}
Replace with: _\L\1
I found this explained in http://vim.wikia.com/wiki/Changing_case_with_regular_expressions but it only works for vim I think.
Any suggestions are welcomed.
I would use this approach:
Find what: m_A{[a-zA-Z]}
Replace with: _a\1
and repeat it for B..Z
Not elegant but should be done quick.

VS2010 Find and Replace

I need help using regular expressions using Find and Replace in VS2010. I want to
Find request("somevar") and replace it with html_encode(request("somevar"))
somevar will be a different for each request("")
Replace request({:q}) with html_encode(request(\1)).