Solved

search for one value within so many characters of another value - within my source code

Posted on 2013-01-30
11
201 Views
Last Modified: 2013-01-30
In my Visual Studio 2010 Pro dev environment, I want to search for the following two phrases (excluding the quotes, mind you):

"href="

and

"Eval("

once the search engine locates the "href=" I want it to begin searching after this phrase up to say, 50 characters, for the phrase "Eval(".

Is this only to be accomplished through a RegEx type search?


What would be the syntax?  Don't know RegEx very well.
0
Comment
Question by:knowlton
  • 6
  • 5
11 Comments
 
LVL 41

Expert Comment

by:guru_sami
ID: 38836131
Can you explain a bit more on what you are trying to accomplish? i.e. why a regex to search in VS?
0
 
LVL 5

Author Comment

by:knowlton
ID: 38836222
It was so I could find examples like THIS in my source code:

  <a id="linkViewDocument" runat="server" href='<%# "~/ViewDoc.Aspx?DocID=" + Eval("BidDocID") + "-" + Eval("BidDocSID") %>'>View Document</a>

Open in new window

               


You might recognize this from another question of mine you just answered.  : )


I would still like to know how to find snippets like this, which have an href and then later on have an EVAL...
0
 
LVL 41

Accepted Solution

by:
guru_sami earned 500 total points
ID: 38836394
Try something like this:
href=.{0,50}Eval\(.*

Open in new window

FYI: Try tool like Expresso for creating/testing regexs..
0
 
LVL 5

Author Comment

by:knowlton
ID: 38836529
Okay.


I'll have to back-burner this for a few hours.

But I will return and give more feedback.

I am sure your RegEx is fine or can be made fine...so the points are yours.  I won't make you wait for me.

Tom
0
 
LVL 5

Author Comment

by:knowlton
ID: 38837661
Follow-up:

href=.{0,50}Eval\(.*


Did not seem to work.
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 5

Author Comment

by:knowlton
ID: 38837685
Well, I take it back.

I downloaded and installed Expresso, and your original Reg Ex worked fine:


expresso test

For some reason it will not work in VS search using RegEx.
0
 
LVL 41

Expert Comment

by:guru_sami
ID: 38837697
Hmmm interesting... I did try it in VS before posting it and it did search the href Eval string that you had in the other post.
Can you post the string you have in your source...
Also make sure you have Regex selected while searching
0
 
LVL 5

Author Comment

by:knowlton
ID: 38837701
svs

Notice above in the screenshot I have "Use Regular Expressions" selected via the GUI.



Register.{0,50}Tag.*

should find this line, correct?  (see below)


<%@ Register TagPrefix="uc2" TagName="BigLabel" Src="~/Controls/BigLabel.ascx" %>
0
 
LVL 41

Expert Comment

by:guru_sami
ID: 38837728
I tested in VS2012...and Register.{0,50}Tag.* works as well.
Not sure may be it's the VS version..Let me see
vs regex search
I think it's the issue with the VS you are using. It has is some of the other interpretations. http://www.codinghorror.com/blog/2006/07/the-visual-studio-ide-and-regular-expressions.html

It is not liking the {0,50}
Check this: http://msdn.microsoft.com/en-us/library/2k3te2cs%28VS.80%29.aspx
http://brianary.blogspot.com/2008/05/visual-studios-nih-regex-syntax.html



This will work: .*Register.*Tag.*
0
 
LVL 5

Author Comment

by:knowlton
ID: 38837819
.*Register.*Tag.*

this worked.  Thank you!


but this does not allow me to specify "match if found within XX characters" correct?
0
 
LVL 41

Expert Comment

by:guru_sami
ID: 38837867
Nope....that's the limitation with the VS version you are using
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
JavaScript error 1 52
Display mvc partial view with errors on parent page 1 26
Error in page 3 45
Gridview alignment 1 4
This article discusses the ASP.NET AJAX ModalPopupExtender control. In this article we will show how to use the ModalPopupExtender control, how to display/show/call the ASP.NET AJAX ModalPopupExtender control from javascript, how to show/display/cal…
As most anyone who uses or has come across them can attest to, regular expressions (regex) are a complicated bit of magic. Packed so succinctly within their cryptic syntax lies a great deal of power. It's not the "take over the world" kind of power,…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now