Search:
Namespaces
Discussions
.NET v1.1
Feedback
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/ht
m
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
Ad
MBR BootFX
Best-of-breed application framework for .NET projects, developed by Matthew Baxter-Reynolds and MBR IT
Copyright © Matthew Baxter-Reynolds 2001-2008. '.NET 247 Software Development Services' is a trading style of MBR IT Solutions Ltd.
Contact Us
-
Terms of Use
-
Privacy Policy
-
www.dotnet247.com