views:

112

answers:

3

In Visual Studio 2008, using Regex, how do I comment out all lines containing the text "xyz"?

+1  A: 
^(.*xyz.*)$

Replace with

// \0

Should do the trick I think. (Not 100% positive here... testing now)

EDIT: Fixed (it's \0 not \1).

Billy3

Billy ONeal
A: 
Find what: ^.*xyz.*

Replace with: //\0

use: Regular expressions.

Paul Creasey
Hmm.. doens't seem to work. It works if the entire like is `xyz`, but not if `xyz` is only part of a line.
Billy ONeal
@Billy, works exactly the same as yours in 2010 rc, which is not surprising, since it is in fact the same as your, without the redundent set of grouping parenthesis!
Paul Creasey
Hmm.. something went really crazy then. I could have swore the regex listed was `^.xyz.` which would not do what the OP needs. The *s are not optional :P
Billy ONeal
A: 

This worked:^.{.xyz.}$\n With the Replace textbox left blank.

Douglas