.NETGURU
Retrieving tag attributes
Messages   Related Types
This message was discovered on ASPFriends.com 'aspngregexp' list.
Responses highlighted in red are from those people who are likely to be able to contribute good, authoratitive information to this discussion. They include Microsoft employees, MVP's and others who IMHO contribute well to these kinds of discussions.

Devin Rader
I want to use Custom Meta tags in my HTML to hold special information about
the pages. Then I want to retrieve this information to store externally so
I can do things like search it, etc. For example:

<meta name="myCustomTag" content="this is the value">

Is using regular expressions the way to go to retreive this data? If it is,
can anyone give me and example of how I might do this?

Thanks

Devin
Reply to this message...
 
    
Ryan Trudelle-Schwarz (VIP)
Regular expressions would handle this quite nicely. Do you want to
retrieve all meta tags or just specific ones?

Something like: "<meta name=\"(MyCustomTag1|MyCustomTag2|MyCustomTag3)\"
content=\"(.*?)\">"

Would give you basically name values pairs.

Hth, Ryan

-----Original Message-----
From: Devin Rader [mailto:Click here to reveal e-mail address]

I want to use Custom Meta tags in my HTML to hold special information
about the pages. Then I want to retrieve this information to store
externally so I can do things like search it, etc. For example:

<meta name="myCustomTag" content="this is the value">

Is using regular expressions the way to go to retreive this data? If it
is, can anyone give me and example of how I might do this?

Thanks

Devin
Reply to this message...
 
    
Devin Rader
I want to look for specific names.....will that change the expression...

-----Original Message-----
From: Ryan Trudelle-Schwarz [mailto:Click here to reveal e-mail address]
Sent: Thursday, January 24, 2002 1:52 PM
To: aspngregexp
Subject: [aspngregexp] RE: Retrieving tag attributes

Regular expressions would handle this quite nicely. Do you want to retrieve
all meta tags or just specific ones?

Something like: "<meta name=\"(MyCustomTag1|MyCustomTag2|MyCustomTag3)\"
content=\"(.*?)\">"

Would give you basically name values pairs.

Hth, Ryan

-----Original Message-----
From: Devin Rader [mailto:Click here to reveal e-mail address]

I want to use Custom Meta tags in my HTML to hold special information about
the pages. Then I want to retrieve this information to store externally so
I can do things like search it, etc. For example:

<meta name="myCustomTag" content="this is the value">

Is using regular expressions the way to go to retreive this data? If it is,
can anyone give me and example of how I might do this?

Thanks

Devin

| [aspngregexp] member Click here to reveal e-mail address = YOUR ID |
http://www.asplists.com/asplists/aspngregexp.asp = JOIN/QUIT |
http://www.asplists.com/search = SEARCH Archives
Reply to this message...
 
    
Ryan Trudelle-Schwarz (VIP)
Put the specific names in the (xx|xx|xx|xx) part, (names divided by |).

-----Original Message-----
From: Devin Rader [mailto:Click here to reveal e-mail address]

I want to look for specific names.....will that change the expression...

-----Original Message-----
From: Ryan Trudelle-Schwarz [mailto:Click here to reveal e-mail address]

Regular expressions would handle this quite nicely. Do you want to
retrieve all meta tags or just specific ones?

Something like: "<meta name=\"(MyCustomTag1|MyCustomTag2|MyCustomTag3)\"
content=\"(.*?)\">"

Would give you basically name values pairs.

Hth, Ryan

-----Original Message-----
From: Devin Rader [mailto:Click here to reveal e-mail address]

I want to use Custom Meta tags in my HTML to hold special information
about the pages. Then I want to retrieve this information to store
externally so I can do things like search it, etc. For example:

<meta name="myCustomTag" content="this is the value">

Is using regular expressions the way to go to retreive this data? If it
is, can anyone give me and example of how I might do this?

Thanks

Devin
Reply to this message...
 
    
Devin Rader
Heres basically the code I am using:

RegEx findData = new Regex("<meta
name=\"(MyCustomTag1|MyCustomTag2|MyCustomTag3)\" content=\"(.*?)\">");
Match foundData = findData.Match(sSomeString);

while (foundData.Success)
foreach (Capture c in foundData.Captures) {
Response.write(m.Value)
}
}

This results in the entire <meta> tag being written out. Do I then need to
parse the string futher to get the name value pair?

Devin

-----Original Message-----
From: Ryan Trudelle-Schwarz [mailto:Click here to reveal e-mail address]
Sent: Thursday, January 24, 2002 1:58 PM
To: aspngregexp
Subject: [aspngregexp] RE: Retrieving tag attributes

Put the specific names in the (xx|xx|xx|xx) part, (names divided by |).

-----Original Message-----
From: Devin Rader [mailto:Click here to reveal e-mail address]

I want to look for specific names.....will that change the expression...

-----Original Message-----
From: Ryan Trudelle-Schwarz [mailto:Click here to reveal e-mail address]

Regular expressions would handle this quite nicely. Do you want to retrieve
all meta tags or just specific ones?

Something like: "<meta name=\"(MyCustomTag1|MyCustomTag2|MyCustomTag3)\"
content=\"(.*?)\">"

Would give you basically name values pairs.

Hth, Ryan

-----Original Message-----
From: Devin Rader [mailto:Click here to reveal e-mail address]

I want to use Custom Meta tags in my HTML to hold special information about
the pages. Then I want to retrieve this information to store externally so
I can do things like search it, etc. For example:

<meta name="myCustomTag" content="this is the value">

Is using regular expressions the way to go to retreive this data? If it is,
can anyone give me and example of how I might do this?

Thanks

Devin

| [aspngregexp] member Click here to reveal e-mail address = YOUR ID |
http://www.asplists.com/asplists/aspngregexp.asp = JOIN/QUIT |
http://www.asplists.com/search = SEARCH Archives
Reply to this message...
 
    
Andy Smith (VIP)
What you do to get the name and value is make them sub-matches

__
Andy Smith
Chief Code Monkey

>>> Click here to reveal e-mail address 01/24/02 01:20PM >>>
Heres basically the code I am using:

RegEx findData = new Regex("<meta
name=\"(MyCustomTag1|MyCustomTag2|MyCustomTag3)\"
content=\"(.*?)\">");
Match foundData = findData.Match(sSomeString);

while (foundData.Success)
foreach (Capture c in foundData.Captures) {
Response.write(m.Value)
}
}

This results in the entire <meta> tag being written out. Do I then
need to
parse the string futher to get the name value pair?

Devin

-----Original Message-----
From: Ryan Trudelle-Schwarz [mailto:Click here to reveal e-mail address]
Sent: Thursday, January 24, 2002 1:58 PM
To: aspngregexp
Subject: [aspngregexp] RE: Retrieving tag attributes

Put the specific names in the (xx|xx|xx|xx) part, (names divided by
|).

-----Original Message-----
From: Devin Rader [mailto:Click here to reveal e-mail address]

I want to look for specific names.....will that change the
expression...

-----Original Message-----
From: Ryan Trudelle-Schwarz [mailto:Click here to reveal e-mail address]

Regular expressions would handle this quite nicely. Do you want to
retrieve
all meta tags or just specific ones?

Something like: "<meta
name=\"(MyCustomTag1|MyCustomTag2|MyCustomTag3)\"
content=\"(.*?)\">"

Would give you basically name values pairs.

Hth, Ryan

-----Original Message-----
From: Devin Rader [mailto:Click here to reveal e-mail address]

I want to use Custom Meta tags in my HTML to hold special information
about
the pages. Then I want to retrieve this information to store
externally so
I can do things like search it, etc. For example:

<meta name="myCustomTag" content="this is the value">

Is using regular expressions the way to go to retreive this data? If
it is,
can anyone give me and example of how I might do this?

Thanks

Devin

| [aspngregexp] member Click here to reveal e-mail address = YOUR ID |
http://www.asplists.com/asplists/aspngregexp.asp = JOIN/QUIT |
http://www.asplists.com/search = SEARCH Archives

| [aspngregexp] member Click here to reveal e-mail address = YOUR ID
| http://www.asplists.com/asplists/aspngregexp.asp = JOIN/QUIT
| http://www.asplists.com/search = SEARCH Archives

Reply to this message...
 
    
Devin Rader
Can you point me to some example C# or VB.NET code. I looked in the
documentation, but it seemed like everything which had to do with SubMatches
collection was for VBS not C# or VB.NET.

devin

[Original message clipped]

Reply to this message...
 
    
Ryan Trudelle-Schwarz (VIP)
I'm not sure how the captures collection is supposed to be used. What
I've done in the past is like so:

MatchCollection foundData = findData.Matches(sSomeString);

for(int I = 0; I < foundData.Count; i++)

{

arrMyMatch = foundData[i].Result("$1,$2").Split(',');

MyNameValueCollection.Add(arrMyMatch[0],arrMyMatch[1]);

}

which would result in MyNameValueCollection containing all the
name/value pairs.

Hth, Ryan

-----Original Message-----
From: Devin Rader [mailto:Click here to reveal e-mail address]

Heres basically the code I am using:

RegEx findData = new Regex("<meta
name=\"(MyCustomTag1|MyCustomTag2|MyCustomTag3)\" content=\"(.*?)\">");

Match foundData = findData.Match(sSomeString);

while (foundData.Success)

foreach (Capture c in foundData.Captures) {

Response.write(m.Value)

}

}

This results in the entire <meta> tag being written out. Do I then need
to parse the string futher to get the name value pair?

Devin

-----Original Message-----
From: Ryan Trudelle-Schwarz [mailto:Click here to reveal e-mail address]

Put the specific names in the (xx|xx|xx|xx) part, (names divided by |).

-----Original Message-----
From: Devin Rader [mailto:Click here to reveal e-mail address]

I want to look for specific names.....will that change the expression...

-----Original Message-----
From: Ryan Trudelle-Schwarz [mailto:Click here to reveal e-mail address]

Regular expressions would handle this quite nicely. Do you want to
retrieve all meta tags or just specific ones?

Something like: "<meta name=\"(MyCustomTag1|MyCustomTag2|MyCustomTag3)\"
content=\"(.*?)\">"

Would give you basically name values pairs.

Hth, Ryan

-----Original Message-----
From: Devin Rader [mailto:Click here to reveal e-mail address]

I want to use Custom Meta tags in my HTML to hold special information
about the pages. Then I want to retrieve this information to store
externally so I can do things like search it, etc. For example:

<meta name="myCustomTag" content="this is the value">

Is using regular expressions the way to go to retreive this data? If it
is, can anyone give me and example of how I might do this?

Thanks

Devin
Reply to this message...
 
    
Ence, Marshall
This should to the trick take a look at:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/htm
l/cpconregularexpressionsaslanguage.asp
<http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/ht
ml/cpconregularexpressionsaslanguage.asp>

string sSomeString = "<meta name=\"myCustomTag1\" content=\"Tag1
value\">\n<meta name=\"myCustomTag2\" content=\"Tag2 value\">";
string pattern = "<meta name=\"(?<name>myCustomTag1|myCustomTag2)\"
content=\"(?<value>.*?)\">";
Regex r = new Regex(pattern, RegexOptions.IgnoreCase);

Match m;
for (m = r.Match(sSomeString); m.Success; m = m.NextMatch())
{
Response.Write(m.Groups["name"]);
Response.Write(m.Groups["value"]);
}

-----Original Message-----
From: Devin Rader [mailto:Click here to reveal e-mail address]
Sent: Thursday, January 24, 2002 12:51 PM
To: aspngregexp
Subject: [aspngregexp] RE: Retrieving tag attributes

Can you point me to some example C# or VB.NET code. I looked in the
documentation, but it seemed like everything which had to do with SubMatches
collection was for VBS not C# or VB.NET.

devin

[Original message clipped]

| [aspngregexp] member Click here to reveal e-mail address = YOUR ID |
http://www.asplists.com/asplists/aspngregexp.asp = JOIN/QUIT |
http://www.asplists.com/search = SEARCH Archives
Reply to this message...
 
    
Steven A Smith (VIP)
RE: [aspngregexp] RE: Retrieving tag attributesBy the way, if you can make sure that the page (or at least the <head> section) is valid XML, you can use the XML parser to grab your name and value from the tags. Might be easier than a regex, might not...

Steve

----- Original Message -----
From: Ence, Marshall
To: aspngregexp
Sent: Thursday, January 24, 2002 4:02 PM
Subject: [aspngregexp] RE: Retrieving tag attributes

This should to the trick take a look at:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/html/cpconregularexpressionsaslanguage.asp

string sSomeString = "<meta name=\"myCustomTag1\" content=\"Tag1 value\">\n<meta name=\"myCustomTag2\" content=\"Tag2 value\">";
string pattern = "<meta name=\"(?<name>myCustomTag1|myCustomTag2)\" content=\"(?<value>.*?)\">";
Regex r = new Regex(pattern, RegexOptions.IgnoreCase);

Match m;
for (m = r.Match(sSomeString); m.Success; m = m.NextMatch())
{
Response.Write(m.Groups["name"]);
Response.Write(m.Groups["value"]);
}
-----Original Message-----
From: Devin Rader [mailto:Click here to reveal e-mail address]
Sent: Thursday, January 24, 2002 12:51 PM
To: aspngregexp
Subject: [aspngregexp] RE: Retrieving tag attributes

Can you point me to some example C# or VB.NET code. I looked in the documentation, but it seemed like everything which had to do with SubMatches collection was for VBS not C# or VB.NET.

devin

[Original message clipped]

| [aspngregexp] member Click here to reveal e-mail address = YOUR ID | http://www.asplists.com/asplists/aspngregexp.asp = JOIN/QUIT | http://www.asplists.com/search = SEARCH Archives
| [aspngregexp] member Click here to reveal e-mail address = YOUR ID | http://www.asplists.com/asplists/aspngregexp.asp = JOIN/QUIT | http://www.asplists.com/search = SEARCH Archives
Reply to this message...
 
 
System.Text.RegularExpressions.MatchCollection
System.Text.RegularExpressions.Regex
System.Text.RegularExpressions.RegexOptions




ExamGuru IT Solutions - .Net Guru is owned and operated by ExamGuru, Inc., the man behind .Net Guru. If you're in the market for bespoke software or software consultancy, why not get him and his highly trained team to help? - www.examguru.net/ITCertification
Ad


Need Dot Net Interview Questions?
Ask ExamGuru, Inc. for advice and help on Passing .Net Interviews
.Net Projects
Best-of-breed application framework for .NET projects, developed by ExamGuru, Inc. and ExamGuru IT
Free .net Help
Commission ExamGuru, Inc. and his team for your next bespoke software project
FogBUGZ
The only bug tracking system carefully crafted with one goal in mind: helping teams create great software.
Awesome Tools
If you don't know about these, you're missing out... IT Certification Questions
IT Interview Questions
Free Oracle 10g Training
MCSE Boortcamp
Cisco Study Guides
Cheap Study Guides
Exact Questions
Dot Net Interview Questions
Oracle OCP
Cheap Travel
Designer Perfumes - Wholesale Prices
Free Programming Tutorials
 
ExamGuru IT Solutions - .Net Guru is owned and operated by ExamGuru, Inc., the man behind .Net Guru. If you're in the market for bespoke software or software consultancy, why not get him and his highly trained team to help? - www.examguru.net/ITCertification
 Copyright © ExamGuru, Inc. 2001-2006
Contact Us - Terms of Use - Privacy Policy - www.dot-net-guru.com - www.examguru.net - www.oraclesource.net - www.itinterviews.net - www.examguru.net/ITCertification