Finding a string using Regular Expression in visual studio 2017 - regex

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

Related

VS Code extension: how to get word type

I'm working on an extension that will display the visual diagram of a regular expression if the cursor is over a RegExp word (ie: could be a simple string "^regex$" or language-specific way to define a regex like in JavaScript /^regex$/).
So I'd need to know what type of element the cursor is over: is there a way to know that using VSCode API ?
If I could detect that the word is either a String or a RegExp, this would be great. I know that other editors like Atom provide APIs to have access to this but didn't find anything in the VS Code docs.
I'm answering my own question: right now (June 2016), it's not possible yet. This is what the official #code twitter told me.
It's planned but there is no timeline.
See: https://twitter.com/warpdesign_/status/739411149855297536

How to find with lookahead in Visual studio 2012 Regex Find and Replace

I am trying to find all using statements that are in cs files that contain a reference to a class anywhere in the file following it.
For example, I want to match using Example.Foo; if BaseClass<SomeClass> is found anywhere in the file following it.
Like such:
I've tried (using Example.Foo;)(?=[.\s\n]*BaseClass\<SomeClass\>[.\s\n]*) but no joy...
UPDATE
For clarity, this is for the VS 2012 IDE Find and Replace dialog.
You need to add a (?s), which enables multiline matching, and also escape the period in using Example.Foo. The regex should be something along the lines of:
(?s)using Example\.Foo;(?=.*BaseClass<SomeClass>)
I figured it out myself.
(?s)using Example\.Foo;(?=(.*|\s\r)BaseClass\<SomeClass\>(.*|\s\r))
This does the trick!
Thanks for the (?s) hint, that was required! +1 for that...

Replace instruction in Visual Studio 2010 with regular expressions

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.

How can I fix this regex in Visual Studio 2010?

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.

Visual Studio 2008 search and replace regex

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