ZekeLA
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/SmallCa lendar.gif " />
<asp:ImageButton ID="btnDeliveryDate" runat="server" Width="16" Height="16" ImageUrl="~/images/SmallCa lendar.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">
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.
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/SmallCa
<asp:ImageButton ID="btnDeliveryDate" runat="server" Width="16" Height="16" ImageUrl="~/images/SmallCa
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.
</td>
<td align="left" class="txt-bodyimportant" bgcolor="93cad9">
<asp:Label runat="server" ID="lblEditCounter">
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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.
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.
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.
\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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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 ;)
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.
ASKER