Showing posts with label regular expressions. Show all posts
Showing posts with label regular expressions. Show all posts

default xml doc comments for c# method parameters

Ever need to quickly generate xml doc comments for C# method parameters? In VS 2010 this can be done with a regular expression find-and-replace.

The “find what” expression: \<param name="{:i}"\>:b*\</param\>

The “Replace with” expression: <param name="\1">The \1.</param>

csharp-method-param-xml-doc-comment-find-and-replace

Not exactly particularly meaningful but it’ll cut down on stylecop warnings…

Visual Studio Regular Expressions and C Preprocessor Macros

Ever run across a need to replace a series of macros (or function calls for that matter) with something almost identical except for a miniscule change?

For example, suppose you've got a debugging macro that takes a format string followed by format variables. Suppose also that this macro doesn't append newlines to the format string. After a while it becomes nearly impossible to distinguish one log message from another. I ask you to suspend disbelief with regard to the obvious question "Why didn't the programmer put a newline at the end of each log message?"

Visual Studio supports regular expressions with a few syntactically small but semantically significant differences from PERL5 regular expressions. PERL5 uses parenthesis both to group/alternate AND capture subexpressions. Visual Studio supports these concepts with distinct operators: parenthesis for grouping/alternation and braces {} for subexpression capture. It refers to subexpressions as tagged expressions.

Anyway, to replace

MYDBGMACRO("the value of x=%d", x);

with

MYDBGMACROS("the value of x=%d\n", x);

using Visual Studio's "Find and Replace" dialog, the find expression is:

{DBGMSG2\(:b*"}{.*}{".*\);}

and the replace expression is:

\1\2\\n\3

That replace expression is a little tricky. The goal is to embed a newline in the format string without splitting up the line in the source code. Only the backslash needs to be escaped.

Searching with Regular Expressions in Internet Explorer

Ever wish you could do a regular expression search on the text of a webpage? FindRegex adds the ability to do this to Internet Explorer. After installing it (click here to download), you can do a regular expression search by right clicking on any web page and choosing "Find Regex".

This has only been tested in Internet Explorer 7+.

NOTE: Ignore the "this can harm your computer" warning on the download page. SkyDrive does that for any file ending in .msi.