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
2010-08-28 23:11:49
That regex does not match your simple example: `class="title"`. there's no character after `title` that isn't a double-quote.
Martinho Fernandes
2010-08-28 23:14:34
Now it matches `class="foo" id="title"` :( Instead of matching with `.` (any character) you should use `[^"]` any character except double-quotes.
Martinho Fernandes
2010-08-28 23:22:38
@Martinho Fernandes thanks, not doing so well with my regexes this morning :S
cofiem
2010-08-28 23:32:43
+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
2010-08-28 23:13:03
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
2010-08-30 12:15:42
@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
2010-08-30 13:13:10