Search:
Namespaces
Discussions
.NET v1.1
Feedback
Using RegExp object in .NET
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.
Jason Salas
-- Copied from [aspngwebservices] to [aspngregexp] by Charles M. Carroll <
Click here to reveal e-mail address
> --Hi everyone,I'm building a Web service for internal use which reporters can use to"wash" their stories and have the thier content be returned treated withformatted hyperlinks, based on a collection of predefined HREFs (mainly justorganizational sites and past storylines we've done), if certain textphrases exist in their articles. The theory is that they'll enter theirtext in a Web form in ASCII and have ultra-sexy HTML sent back to them,which they will then plug into their stories. It's basically a linkingservice brought forth by my laziness.For example, if the phrase "Governor of Guam" is entered, the WS will return<a href="
http://www.guamdailyviews.com"
;>Governor of Guam</a>. Somethinglike that.I'm thinking the best way to do this would be to use Regular Expressions,but can the RegExp object hold arrays or collections or other multi-valueobject? I've got about 80 known HREFs, and it will grow over time as wediscover new links.Any ideas?Thanks much,Jason
Reply to this message...
Wayne King
The .NET RegExp object only accepts individual strings as input for =
regular expression patterns. From your explanation it sounds like you =
want to make a string that is giant alternation pattern with more than =
80 choices. Something like: "Governor of Guam|Carl Gutierrez|et cetera"
Using a regex in this manner is extremely simple, but on the other hand, =
if you are concerned about speed, there may be more efficient ways to =
implement this kind of searching.
-Wayne
-----Original Message-----
From: Jason Salas [mailto:
Click here to reveal e-mail address
]
Sent: Sunday, November 25, 2001 4:24 AM
To: aspngregexp
Subject: [aspngregexp] Using RegExp object in .NET
-- Copied from [aspngwebservices] to [aspngregexp] by Charles M. Carroll =
<
Click here to reveal e-mail address
> --
Hi everyone,
I'm building a Web service for internal use which reporters can use to
"wash" their stories and have the thier content be returned treated with
formatted hyperlinks, based on a collection of predefined HREFs (mainly =
just
organizational sites and past storylines we've done), if certain text
phrases exist in their articles. The theory is that they'll enter their
text in a Web form in ASCII and have ultra-sexy HTML sent back to them,
which they will then plug into their stories. It's basically a linking
service brought forth by my laziness.
For example, if the phrase "Governor of Guam" is entered, the WS will =
return
<a href=3D"
http://www.guamdailyviews.com"
;>Governor of Guam</a>. =
Something
like that.
I'm thinking the best way to do this would be to use Regular =
Expressions,
but can the RegExp object hold arrays or collections or other =
multi-value
object? I've got about 80 known HREFs, and it will grow over time as we
discover new links.
Any ideas?
Thanks much,
Jason
Reply to this message...
Steven A Smith (VIP)
And that expression would only match or not match. It wouldn't match a
correspoding keyword with a particular URL. Looping through an array of
individual keywords and replacing with their associated link seems like the
best bet to me.
Steve
Steven Smith
Click here to reveal e-mail address
President, ASPAlliance.com
http://aspalliance.com
The #1 ASP.NET Community
http://aspsmith.com
ASP.NET Training for ASP Developers
Get The Book: ASP.NET By Example
http://www.amazon.com/exec/obidos/ASIN/0789725622/stevenatorasp/
----- Original Message -----
From: "Wayne King" <
Click here to reveal e-mail address
>
To: "aspngregexp" <
Click here to reveal e-mail address
>
Sent: Sunday, November 25, 2001 8:00 PM
Subject: [aspngregexp] RE: Using RegExp object in .NET
The .NET RegExp object only accepts individual strings as input for regular
expression patterns. From your explanation it sounds like you want to make a
string that is giant alternation pattern with more than 80 choices.
Something like: "Governor of Guam|Carl Gutierrez|et cetera"
Using a regex in this manner is extremely simple, but on the other hand, if
you are concerned about speed, there may be more efficient ways to implement
this kind of searching.
-Wayne
-----Original Message-----
From: Jason Salas [mailto:
Click here to reveal e-mail address
]
Sent: Sunday, November 25, 2001 4:24 AM
To: aspngregexp
Subject: [aspngregexp] Using RegExp object in .NET
-- Copied from [aspngwebservices] to [aspngregexp] by Charles M. Carroll
<
Click here to reveal e-mail address
> --
Hi everyone,
I'm building a Web service for internal use which reporters can use to
"wash" their stories and have the thier content be returned treated with
formatted hyperlinks, based on a collection of predefined HREFs (mainly just
organizational sites and past storylines we've done), if certain text
phrases exist in their articles. The theory is that they'll enter their
text in a Web form in ASCII and have ultra-sexy HTML sent back to them,
which they will then plug into their stories. It's basically a linking
service brought forth by my laziness.
For example, if the phrase "Governor of Guam" is entered, the WS will return
<a href="
http://www.guamdailyviews.com"
;>Governor of Guam</a>. Something
like that.
I'm thinking the best way to do this would be to use Regular Expressions,
but can the RegExp object hold arrays or collections or other multi-value
object? I've got about 80 known HREFs, and it will grow over time as we
discover new links.
Any ideas?
Thanks much,
Jason
| [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...
dagon
Steve,
It can be made to match a corresponding keyword, by using a
MatchEvaluator
in the Replace method, which would return the new corresponding string to
replace the match with (from a Hashtable, for example).
A simple example (off the top of my head):
...
private string fHandle(oMatch) {
return oHash[oMatch.ToString().ToLower()];
}
public string GetResult(sOrig) {
return
Regex
.Replace(sOrig,sPattern,new
MatchEvaluator
(fHandle),
RegexOptions
.IgnoreCase);
}
...
That said, it would still be better (even though less cool :)) to loop and
replace with say:
foreach (string sItem in oHash.Keys) {
sOrig=
Regex
.Replace(sOrig,"\\b("+sItem+")\\b",oHash[sItem],
RegexOptions
.Igno
reCase);
}
because of the simplicity of this task, but the
MatchEvaluator
is nice for
more complex things.
- dagon.
-----Original Message-----
From: Steven A Smith [mailto:
Click here to reveal e-mail address
]
Sent: Monday, November 26, 2001 07:50
To: aspngregexp
Subject: [aspngregexp] RE: Using RegExp object in .NET
And that expression would only match or not match. It wouldn't match a
correspoding keyword with a particular URL. Looping through an array of
individual keywords and replacing with their associated link seems like the
best bet to me.
Steve
Steven Smith
Click here to reveal e-mail address
President, ASPAlliance.com
http://aspalliance.com
The #1 ASP.NET Community
http://aspsmith.com
ASP.NET Training for ASP Developers
Get The Book: ASP.NET By Example
http://www.amazon.com/exec/obidos/ASIN/0789725622/stevenatorasp/
----- Original Message -----
From: "Wayne King" <
Click here to reveal e-mail address
>
To: "aspngregexp" <
Click here to reveal e-mail address
>
Sent: Sunday, November 25, 2001 8:00 PM
Subject: [aspngregexp] RE: Using RegExp object in .NET
The .NET RegExp object only accepts individual strings as input for regular
expression patterns. From your explanation it sounds like you want to make a
string that is giant alternation pattern with more than 80 choices.
Something like: "Governor of Guam|Carl Gutierrez|et cetera"
Using a regex in this manner is extremely simple, but on the other hand, if
you are concerned about speed, there may be more efficient ways to implement
this kind of searching.
-Wayne
-----Original Message-----
From: Jason Salas [mailto:
Click here to reveal e-mail address
]
Sent: Sunday, November 25, 2001 4:24 AM
To: aspngregexp
Subject: [aspngregexp] Using RegExp object in .NET
-- Copied from [aspngwebservices] to [aspngregexp] by Charles M. Carroll
<
Click here to reveal e-mail address
> --
Hi everyone,
I'm building a Web service for internal use which reporters can use to
"wash" their stories and have the thier content be returned treated with
formatted hyperlinks, based on a collection of predefined HREFs (mainly just
organizational sites and past storylines we've done), if certain text
phrases exist in their articles. The theory is that they'll enter their
text in a Web form in ASCII and have ultra-sexy HTML sent back to them,
which they will then plug into their stories. It's basically a linking
service brought forth by my laziness.
For example, if the phrase "Governor of Guam" is entered, the WS will return
<a href="
http://www.guamdailyviews.com"
;>Governor of Guam</a>. Something
like that.
I'm thinking the best way to do this would be to use Regular Expressions,
but can the RegExp object hold arrays or collections or other multi-value
object? I've got about 80 known HREFs, and it will grow over time as we
discover new links.
Any ideas?
Thanks much,
Jason
| [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.MatchEvaluator
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