Re: Regular Expression Question
- From: "Kevin Spencer" <unclechutney@xxxxxxxxxxxx>
- Date: Tue, 20 Feb 2007 12:47:49 -0500
The best way I can think of it is using the following:
(?i)(?:<a[^>]*href="?){1}(?<url>[^\s>"]*)
The first expression is a mode modifier, indicating that the regex is
case-insensitive. I prefer to use these rather than setting options. The
second part is a non-capturing group that defines the beginning of a link
tag, and it specifies exactly one time. Because an HTML tag may or may not
use quotes in the attribute value, the quote prior to the URL is optional (0
or 1 time). After that there is a single group named "url" that contains the
URL you're looking for. It is defined as any number of any character that is
NOT a space, right angle bracket, or a quote. You replace the group using
the Regex.Replace override that takes a MatchEvaluator delegate.
--
HTH,
Kevin Spencer
Microsoft MVP
Software Composer
http://unclechutney.blogspot.com
I had the same problem once. Fixed it using the same solution.
"Matthias S." <matthias&AtSign&emvoid$dot$com> wrote in message
news:Oj5wl4QVHHA.5100@xxxxxxxxxxxxxxxxxxxxxxx
Hi there,
I'm trying to build a regular expression which will do a replace for me.
I'm
getting grey hair on this one:
here is my input string:
<a href="http://test.com/fun.jpg" target="_blank">my fun pic</a>
I'd like to turn this into the following:
[url=my fun pic]http://test.com/fun.jpg[/url]
Can somebody help me building such a regular expression? Any help is
greatly
appreceated. Thanks in advance!
Matthias
.
- References:
- Regular Expression Question
- From: Matthias S.
- Regular Expression Question
- Prev by Date: Re: event handler in VS 2005 designer
- Next by Date: RE: Binding custom object to formview
- Previous by thread: Regular Expression Question
- Next by thread: Counting CheckBoxes
- Index(es):
Relevant Pages
|