Solved

Reg Ex Search c#

Posted on 2011-02-14
3
347 Views
Last Modified: 2012-05-11
Hi

I am new to regular expressions.  I am doing search in text of HTML. What I want to do is find a  tag then from that point find the next "</div>" tag

I have this

            String body = sb.ToString();
            String Start = "<div><a class=\"resultName\"";
            String Stop = "</div>";

            Match m;
            m = new Regex(Start, RegexOptions.Singleline | RegexOptions.IgnoreCase).Match(body);
            int i = m.Index;

now  find from i how many characters away is Stop "</div>"

so instead of  somethikng like this

            txtList.Text = body.Substring(i, 200);

But what I would like to do is txtList.Text = body.Substring(i, x);

Where x is the number of characters to the next "</div>"

Hope that was expained well

Thanks


0
Comment
Question by:Charles Baldo
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 20

Expert Comment

by:informaniac
ID: 34894268
Can't u use bodymsubstring(i,body.indexOf("<div>"))
0
 
LVL 20

Expert Comment

by:informaniac
ID: 34894299
Sry shd be body.Substring....
0
 
LVL 75

Accepted Solution

by:
käµfm³d   👽 earned 500 total points
ID: 34894827
Try something like this:
String body = sb.ToString();
String Start = "<div><a class=\"resultName\"";
String Stop = "</div>";

// Here, .*? means find zero-or-more ( * ) of any
//  character ( . ), but find only the minimum number
//  that will satisfy a valid match ( ? )
String pattern = string.Concat(Start, "(.*?)", Stop);

Match m;
m = Regex.Match(body, pattern, RegexOptions.Singleline | RegexOptions.IgnoreCase);
int i = m.Index + m.Length;

Open in new window

0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
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…
Suggested Courses

630 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