I'm trying to search using this regex in Visual Studio, but it doesn't work.
<(script|link)\b(.*?)Site.css(.*?)(script>|/>)
After reading this article I changed it to
\<(script|link)\b(.*?)Site.css(.*?)(script\>|/\>)
But it still doesn't work. What am i doing wrong?
Your help is much appreciated :)
look here...it's quite old now but nice to read http://www.codinghorror.com/blog/2006/07/the-visual-studio-ide-and-regular-expressions.html
Following the guide above I tried to translate your regular expression. Unforunately I couldn't find anything suitable for the non-greedy quantifier *? and was forced to stick with the greedy one *. That's my guess (successfully tested on visual studio 2010):
\<{script|link}.+Site.css.*{/\>|script\>}
I feel to suggest you a different editor when you want to intensively use regular expressions on Visual Studio resource files like xml stuff. My personal choice was PowerGrep but that's a commercial product. I'm sure there are lots of them for free on the internet.
Related
Hello can anyone help me create a reg expression that would find this in my project?
#Html.Raw(customItem.Fields["Body"].ToString())
I need to change out the "customItem" and "Body" text with a wild card.
Are you looking for something like this?
\#Html\.Raw\((.+?)\.Fields\["(.+?)"\]\.ToString\(\)\)
You can see it working here
For example, I have the following lines:
//sys.log(siteNameToPrepare);
//sys.log(siteNameToPrepare);
// sys.log("downloadFolder: "+downloadFolder);
// lorem ipsum ...
arbitrary codes here...
var a = _POST;
sys.log("groupManagementHandler.jhp _POST is not object");
sys.log("groupManagementHandler.jhp _POST is not object");
I only want to match sys.log(xxx) that is not commented out.
I tried to use the following regex:
[^/ ]sys.log
on the search bar (Ctrl+Shift+F), with Regex ON, to find the uncommented sys.log within files of a folder.
It matches uncommented lines in several files, however, I missed some lines that has couple of whitespaces in front of sys.log.
My question is how to match those lines? What am I missing here?
Seems like I couldn't find the answer in Google and Stackoverflow, I found this one, but this one is for Visual Studio, not Visual Studio Code.
Visual Studio Search Uncommented Code
Here's the error message I got by using the look ahead pattern:
Thanks to #Wiktor Stribiżew, now I can confirm that the regex lookahead pattern for searching within files works in older Visual Studio Code (V1.2.0) but not works in Version 1.17.1.
So this question may somehow can be seen as a duplicated question due to the bug of newer version VS code, that led me to post this question.
For someone who wants to know the answer right away, here it is as suggested by #Mark at the comment section of my question:
First open the "search in files" field using Ctrl+Shift+F
Turn on the Regex function (right-most button of the input field)
Put the following regex:
^\s*sys.log
or this regex also works
^[^/\n](?:/[^/\n]+)*sys.log
The above regex-es work for my case.
Before I got this answer, we had a discussion with #Tim and #Wiktor, they both suggested a lookahead regex pattern, and that pattern actually works on older version (V.1.2.0) of Visual Studio Code as #Wiktor pointed out. But apparently,
the advanced Regex feature for searching in files is no longer supported since V1.12.0 version. However, it's still working if you search within the file using Ctrl+F.
Thanks to #Tim, #Wiktor and #Mark who have helped to clarify things out.
was wondering if anyone could help me find the regular expression for this problem. I'd like to replace the following using Visual Studio 2010's built in Find/Replace function:
_batch.AddInstruction(InstructionType.Update, "LEG_RES_ID", "N")
with
_batch.AddInstruction(InstructionType.Update, BpcFields.LegResId, "N")
The "LEG_RES_ID" is a placeholder, multiple different strings can occur here. For any string in that position, the equivalent member of BpcFields will be a Pascal-case version of the same string, without the underscores, as in the example above.
Many thanks in advance!
I'd look at this answer and try to use macros. It seems that it is not possible to changhe the case of text only with regexp unless you have another editor (for example EditPad pro according to this question).
Another workaround would be to create a program that performs the task you need on text files and use it on your source.
I have a large solution with a lot of lines that I need to replace.
In Visual Studio, you can search and replace with the aid of regular expressions.
I want to replace lines like:
rst.Fields("CustomerName").Value
rst.Fields("Address").Value
rst.Fields("Invoice").Value
To:
row("CustomerName").ToString()
row("Address").ToString()
row("Invoice").ToString()
Thus keeping the dynamic text part, which can vary.
Is this possible and how?
Update, solution:
Search: rst.Fields{\(.*\)}\.Value
Replace: rst\1.ToString()
Thanks JaredPar!
Try the following
Search Expression: ASpecificCommand(\(.*\))\.ASpecificProperty
Replace Expression: ATotallyDifferentCommand\1.ATotallyDifferentProperty
Note: This is not a perfect solution. Since there are (s involved and hence matching of nested parens, a regex won't ever be a perfect solution. However it should get the job done for the specific pattern you posted
The answer and solution provided helpful in doing a find-replace on messageboxes.
This worked in Visual Studio 2008 (VB .NET):
Example:
MessageBox.Show("Invalid Entry","Error")
Find What:
MessageBox.Show{(.*,*)}
Replace WIth:
Error.ShowError\1\2
Results in:
Error.ShowError("Invalid Entry","Error")
Looks like you have it nailed. It's what is called a "tagged expression" and you can see another example here:
http://blogs.msdn.com/b/zainnab/archive/2010/09/12/replace-in-files-tagged-expressions-vstipfind0016.aspx
I'm looking for a decent tool that can do search and replace over multiple files, with regular expression syntax I'm use to in C#. Normally I would do this in Visual Studio, except it has the strangest regex syntax (and this is meant to be faster than just replacing the text in the files manually).
So far I've tried windows grep but it didn't like the regex below. The regex in question is
<see cref="(?<class>.+)">(.+)</see>
To replace with
<see cref="${class}"/>
Alternatively converting this to Visual Studio's syntax would be fine!
Jeff has a whole post on this on his blog.
In Visual Studio, find:
\<see cref="{:i}"\>.*\</see\>
and replace with:
<see cref="\1"/>
{} is the VS grouping operator. It is not named. In replacements \n is used for the value of the n-th group in the find expression.
You can tweak the :i and .* parts if you need to account for new lines or other whitespace.
In Visual Studio you can do this with the following Reg Ex:
\<see cref="{.+}"\>.+\</see\>
Replace:
<see cref="\1" />
Remember to select Use/Regular Expressions in the Find and Replace dialog.
I've long been thinking it sucks that Visual Studio does not support the same Regular Expression syntax as the .Net framework.
There are a few choices:
If it's something you do regularly, I would go with PowerGrep as it is probably the most complete and user-friendly tool for this.
Its sibling, RegexBuddy also has a Grep functionality, albeit not as comprehensive.
If you're not afraid of Perl, you can also use its command line as a search and replace tool.
Otherwise, there is still the venerable sed that works on Windows.
notepad++ is quite popular and lightweight and has this functionality, have you tried that?:
http://notepad-plus.sourceforge.net/uk/site.htm
EDIT:
It would appear my link is outdated and this usage is only quite recent:
http://www.opensourcereleasefeed.com/release/show/notepad-v5-2-released-replace-in-files-feature-added
You can use the .NET Regular Expression AddIn to allow you to use .NET regexes with Visual Studio. It's on CodeProject at http://www.codeproject.com/KB/macros/VS2005RegexAddIn.aspx.
Mike