views:

42

answers:

2

Is there a way in Visual Studio to find usages of a CSS class? Right now I have to do search the entire project to find all usages. Sometimes its hard if the class is named as something generic like "title". I will get all of these search results that have nothing to do with usage of that class.

A: 

By usages of a CSS class, do you mean:

... class="title" ...

If so, then you could use the regex search in VS to find these:

class=".*title.*"

Edit: See @Martinho Fernandes response for a working regex.

cofiem
That regex does not match your simple example: `class="title"`. there's no character after `title` that isn't a double-quote.
Martinho Fernandes
Now it matches `class="foo" id="title"` :( Instead of matching with `.` (any character) you should use `[^"]` any character except double-quotes.
Martinho Fernandes
@Martinho Fernandes thanks, not doing so well with my regexes this morning :S
cofiem
+1  A: 

I don't know of any built-in way of doing this in Visual Studio, but some regex magic might do the trick. Try searching for this:

class="[^"]*<title>
Martinho Fernandes
this works to a point. can this query be modified to match the whole word? right now it finds classes that have title as part of their name (ex: class="documenttitle")
dev.e.loper
@dev.e.loper: I knew there was something missing. The added `<>` should do the trick. Please note that this regex syntax is specific to the Visual Studio search facilities. In most other flavors of regex, word boundaries are matched with `\b`.
Martinho Fernandes