474,044 Members | 3,581 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Get an inner-text from a regular expression

Spippo
15 New Member
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 2764
PareshRathod
28 New Member
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.Mat ches(webBrowser 1.Document.Body .InnerHtml, pattern,RegexOp tions.IgnoreCas e);
foreach (Match obj in match)
{
Console.WriteLi ne(obj.Groups[2].Value.ToString () + " => " + obj.Groups[4].Value.ToString ());
}

Notes:
1. () define groups in search pattern.
2. RegexOptions.Ig noreCase 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 New Member
OMG, Thanks a lot.
I will do as you requested:

Thanks dear!!!!!!!!

You are my god
Jan 2 '08 #3
PareshRathod
28 New Member
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
10975
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 object's members. now, i have an enclosing class, which has a static factory method (loads an instance of the enclosing class from a serialized file, and returns it). during the loading, some initialization takes place. one of the initialization...
3
6441
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, Employees.LastName, TerritoryID, Employees.EmployeeID, RegionID, ProductID from Employees
8
1530
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 "document.write(outer.inner);" on the global
6
9340
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: tblEmployees empId -- EmpName -- EmpRole -- EmpManager -------....------------.... ---------....--------------- 1........ dan yella..........1..........2
52
6461
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 variations(combination of fields), - then act on each group in some way ...eg ProcessRs (oRs as RecordSet)... the following query will get me the distinct groups
5
2447
by: Martijn Mulder | last post by:
A construction like this: class Outer { class Inner:Outer { } } compiles without problem but does it introduce infinity?
1
1631
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, technically). I want to declaring an unrelated "Thing" class to be a friend of the inner class. However, since the inner class is private, the compiler complains. Here's what the code looks like: ====================================================...
9
4704
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
4274
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 reference, which means it is only collected by the mark-and-sweep collector, not by reference counting. Here is some code that demonstrates it: === def outer():
2
4610
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, tblPeribadi.Taraf_Jawatan, tblGroup.Keterangan AS Kumpulan,tblPeribadi.Gred,tblBusiness_Area.Keterangan AS Business_Area,tblCost_Center.Keterangan AS Kod_Pusat_Kos, tblPeribadi.IC_Baru, tblPeribadi.IC_Lama, ...
0
10545
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10337
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
12137
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
11601
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
12020
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
8696
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
7867
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
5413
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3970
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.