Link to home
Start Free TrialLog in
Avatar of ZekeLA
ZekeLAFlag for United States of America

asked on

VS 2005 Find in Files Regex needed to locate malformed hex codes

I need to find all hex codes in my asp.net web app that do not have a leading pound sign. That is, I need to find a line containing something like bgcolor="a9B0f3" but not find bgcolor="#a9B0f3".

I'm using Visual Studio 2005. I tried using Find in Files with this pattern:

^.*"([a-f]|[A-F]|[0-9]){6}".*$

but it only returned these lines for a test file:

<asp:ImageButton ID="btnCompoundingDate" runat="server" Width="16" Height="16" ImageUrl="~/images/SmallCalendar.gif" />
<asp:ImageButton ID="btnDeliveryDate" runat="server" Width="16" Height="16" ImageUrl="~/images/SmallCalendar.gif">

even though the test file includes lines like these:

                        <AlternatingItemStyle BackColor="#E6E6E6" />
                                    <td style="background-color: #93cad9;" rowspan="100%">
                                        <img runat="server" src="~/images/spacer_1pix.gif" width="10" id="STRImg1">
                                    </td>
                                    <td align="left" class="txt-bodyimportant" bgcolor="93cad9">
                                        <asp:Label runat="server" ID="lblEditCounter">&nbsp;

It should list the next to last line with the bgcolor="93cad9" attribute but none of the other ones.

When I remove the quotes from the regex, it will find the "#E6E6E6" but not hex codes where lower case letters are also used (such as bgcolor="#93cad9").

Can someone please help me with the correct expression for VS2005 to find the hex codes without the leading pound sign?

Thanks.
ASKER CERTIFIED SOLUTION
Avatar of Pui_Yun
Pui_Yun
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of ZekeLA

ASKER

That didn't seem to work. Neither one found any matches.
SOLUTION
Avatar of kaufmed
kaufmed
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of ZekeLA

ASKER

While that regex is better than what I had, it still does not work in VS 2005. Did you test it in VS 2005 or were you just providing a general regex solution? I think my problem may not be the regex so much as VS.
Avatar of ZekeLA

ASKER

Also, why do you use ^6 and not {6}? In the cheat sheet I use, ^ represents the start of the line.
Because the regex codes in VS's library are not the same codes that other environments like Perl, C#, etc.  use. If you view the "Complete Character List", you will see that repetition is achieved through the ^n syntax, where "n" is the number of repetitions.

Also, in VS find/replace, {n} is not the repetition construct--it is the tagging/grouping construct that allows you to use backreferences. This is similar to the parentheses constructs available in the languages I mentioned above.
As a further example, your cheat sheet probably lists

    \s

as the whitespace marker. In VS find/replace,

    :b

is the marker. I don't believe your cheat sheet is going to help you inside the IDE--VS help will do that. Use your cheat sheet for the patterns you write in code.
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Of course if you do include the lowercase characters as I did, then you do not have to worry about whether "Match Case" is checked  ;)
Avatar of ZekeLA

ASKER

All of the proposed solutions are now working. Something weird must have been going on since I know I checked the various options carefully. I'm increasing points so I can distribute the wealth more fairly.