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.
LVL 1
ZekeLAAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Pui_YunCommented:
Hi ZekeLA,
Try this to find the lines - highlights the line:
^.*\":h^6\".*$

or this to highlight just the hex characters and the quotes:
\":h^6\"

Hope this helps.
P.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
ZekeLAAuthor Commented:
That didn't seem to work. Neither one found any matches.
käµfm³d 👽Commented:
This appears to be what you are after:
"[a-fA-F0-9]^6"

Open in new window

OWASP: Forgery and Phishing

Learn the techniques to avoid forgery and phishing attacks and the types of attacks an application or network may face.

ZekeLAAuthor Commented:
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.
ZekeLAAuthor Commented:
Also, why do you use ^6 and not {6}? In the cheat sheet I use, ^ represents the start of the line.
käµfm³d 👽Commented:
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.
käµfm³d 👽Commented:
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.
Pui_YunCommented:
I've tested it in VS 2005, and it worked for me.  I think kaufmed expression might be better, however, I would just use this (will match for both cases as long as you don't check the match case box):
\"[A-F0-9]^6\"

Here's the microsoft document about the regexes in VS 2005:
http://msdn.microsoft.com/en-us/library/aa293063%28VS.71%29.aspx

I was using ^6 because the regex has a different syntax in VS 2005, if scroll down and find "Repeat n times" in the page.  You'll see it uses a ^n notation.

Hope this helps.
P.
käµfm³d 👽Commented:
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  ;)
ZekeLAAuthor Commented:
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.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.