473,323 Members | 1,589 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,323 software developers and data experts.

Get an inner-text from a regular expression

Spippo
15
Hello

Is it possible to retrieve then inner-text from a link with regular expressions?
For example, I can retrieve all links with regular expressions. With:

Expand|Select|Wrap|Line Numbers
  1. string pattern = @"<a href="".*"">.*</a>";
  2. MatchCollection mc = Regex.Matches(webBrowser1.Document.Body.InnerHtml, pattern);
  3.  
  4. foreach(object obj in mc)
  5. {
  6.     Console.WriteLine(obj.ToString());
  7. }
  8.  
So i get the following matches:

Expand|Select|Wrap|Line Numbers
  1. <a href="http://www.thescripts.com">The Scripts</a>
  2. <a href="http://www.mysite.com">My Site</a>
  3. <a href="http://www.anothersite.com">Yet another site</a>
  4.  
But is it also possible to retrieve only the innertexts? So I would get the following results:

Expand|Select|Wrap|Line Numbers
  1. The Scripts
  2. My Site
  3. Yet another site
  4.  
Or even better, more innertexts in one item like:
Expand|Select|Wrap|Line Numbers
  1. http://www.thescripts.com The Scripts
  2. http://www.mysite.com My Site
  3. http://www.anothersite.com Yet another site
  4.  
Thanks
Dec 30 '07 #1
3 2737
Hi Guys,

Nice to see that somebody needs my Regular Expression Talent...
Try This,
This will solve your problem:

string pattern = @"(\<a href="")(.*?)(""\>)(.*?)\</a\>";
MatchCollection match=Regex.Matches(webBrowser1.Document.Body.Inne rHtml, pattern,RegexOptions.IgnoreCase);
foreach (Match obj in match)
{
Console.WriteLine(obj.Groups[2].Value.ToString() + " => " + obj.Groups[4].Value.ToString());
}

Notes:
1. () define groups in search pattern.
2. RegexOptions.IgnoreCase implements case insensitive search.
3. object -> Match in foreach to retrieve groups.

Say thanks dear if you like it, it shows our goodness.

Paresh

Hello

Is it possible to retrieve then inner-text from a link with regular expressions?
For example, I can retrieve all links with regular expressions. With:

Expand|Select|Wrap|Line Numbers
  1. string pattern = @"<a href="".*"">.*</a>";
  2. MatchCollection mc = Regex.Matches(webBrowser1.Document.Body.InnerHtml, pattern);
  3.  
  4. foreach(object obj in mc)
  5. {
  6.     Console.WriteLine(obj.ToString());
  7. }
  8.  
So i get the following matches:

Expand|Select|Wrap|Line Numbers
  1. <a href="http://www.thescripts.com">The Scripts</a>
  2. <a href="http://www.mysite.com">My Site</a>
  3. <a href="http://www.anothersite.com">Yet another site</a>
  4.  
But is it also possible to retrieve only the innertexts? So I would get the following results:

Expand|Select|Wrap|Line Numbers
  1. The Scripts
  2. My Site
  3. Yet another site
  4.  
Or even better, more innertexts in one item like:
Expand|Select|Wrap|Line Numbers
  1. http://www.thescripts.com The Scripts
  2. http://www.mysite.com My Site
  3. http://www.anothersite.com Yet another site
  4.  
Thanks
Jan 1 '08 #2
Spippo
15
OMG, Thanks a lot.
I will do as you requested:

Thanks dear!!!!!!!!

You are my god
Jan 2 '08 #3
Hi Guy,

No need to put me in that much big category...
Just a simple thanks can work.... :)

Have a nice time..
Paresh

OMG, Thanks a lot.
I will do as you requested:

Thanks dear!!!!!!!!

You are my god
Jan 2 '08 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Murat Tasan | last post by:
hi, i am having a small problem with constructing an inner class. i am using an inner class (and not a static nested class) because the methods of the inner class need access to the enclosing...
3
by: Prem | last post by:
Hi, I am having many problems with inner join. my first problem is : 1) I want to know the precedance while evaluating query with multiple joins. eg. select Employees.FirstName,...
8
by: olov.johansson | last post by:
Hi, given two nested functions: function outer() { function inner() { } } Is it determined by the ECMAScript standard that inner should be a property of outer, thus a...
6
by: dmonroe | last post by:
hi group -- Im having a nested inner join problem with an Access SQl statement/Query design. Im running the query from ASP and not usng the access interface at all. Here's the tables: ...
52
by: MP | last post by:
Hi trying to begin to learn database using vb6, ado/adox, mdb format, sql (not using access...just mdb format via ado) i need to group the values of multiple fields - get their possible...
5
by: Martijn Mulder | last post by:
A construction like this: class Outer { class Inner:Outer { } } compiles without problem but does it introduce infinity?
1
by: mrstephengross | last post by:
I'm making progress on mixing templates with friends (sounds like a drinking game, huh?). Anyway, here's the situation. I've got an "Outer" class with a private "Inner" class (sub-class,...
9
by: Matthias Buelow | last post by:
Hi folks, I've got something like: class Outer { int f(); friend class Inner; class Inner { int g() {
3
by: from.future.import | last post by:
Hi, I encountered garbage collection behaviour that I didn't expect when using a recursive function inside another function: the definition of the inner function seems to contain a circular...
2
by: MATTXtwo | last post by:
I have this store procedure to select data from table with join like this...SELECT tblPeribadi.Personel_No, tblPeribadi.Nama,tblCompany.Keterangan as Company_Code, tblPeribadi.Jawatan,...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.