bynary
bynary

Reputation: 901

How do I search for html tags in Visual Studio 2010?

I am trying to find all instances of <script> in my solution in Visual Studio 2010. Here are the steps I take:

  1. Type CTRL+Shift+F
  2. Type <script into the "Find what:" textbox
  3. Click "Find All" button

I only get results where <script> is in a string (i.e. var foo = "<script>do something</script>, where <script> was the only html tag in a .cshtml file, or where <script> is in a comment (i.e. //Close the <script> tag).

I tried a Regular Expression search with \<script\> which yielded 0 results. I've had the same results searching for <a>. I haven't done an exhaustive test of the Visual Studio 2010 search with all html tags, but it seems to be equally broken for all html tags.

How can I find what I'm looking for in my source code?

Upvotes: 0

Views: 656

Answers (1)

valverij
valverij

Reputation: 4951

My guess is that your script tags are defined like this

<script type="text/javascript"></script>

Instead of this:

<script></script> 

So try this out with Use Regular Expressions checked in the Find Options:

  1. Hit CTRL+F
  2. Go to "Find in files..."
  3. use this expression:

    \</*script[ ]*.*\>

It should find all of your opening and closing <script> tags. Be careful if you're trying to do a find and replace, though. When I ran it, I got some results from within a couple third party javascript files (including knockout).

I know it's not exactly the best regex syntax, but the Visual Studio find syntax is apparently different from the regular .NET regex.

Upvotes: 1

Related Questions