Yogurt The Wise
Yogurt The Wise

Reputation: 4499

Using Visual Studio regex to find css name within class attribute

Trying to use VS 2010 regex to make specific changes to a css class name.

Want to find every "required" that is in a class attribute.

1 - class="required"
2 - class="c1 required c2"
3 - class="c1"
4 - class="c1 required c2 c3"
5 - class="required c2"
6 - class="c1 c2"
7 - class="c1 c3 required "

So the expression should only match 1 2 4 5 7

The "required" word is used by some other stuff that can not be changed, so i can't just search for "required" and replace it.

Upvotes: 1

Views: 1201

Answers (1)

ridgerunner
ridgerunner

Reputation: 34435

I am assuming you are looking for a regex to use in the VS 2010 IDE Find & Replace box.

The Visual Studio 2010 IDE uses a non-standard regex syntax (See: Regular Expressions (Visual Studio) - note that it uses curly braces to enclose capturing groups). If my understanding of the syntax and usage is correct, the following may do the trick:

Find this:

{class[ \t]*=[ \t]*"[^"]*}required

And replace it with this:

\1replacementtexthere

Note that I do not have VS 2010 so I cannot test the above solution.

Upvotes: 3

Related Questions